当前位置 类层次(JDK) 所有类(JDK) 所有域和方法(JDK)

类 java.io.InputStreamReader

java.lang.Object
   |
   +----java.io.Reader
           |
           +----java.io.InputStreamReader

public class InputStreamReader
extends Reader
下列类的父类:
FileReader

一个 InputStreamReader 类是从字节流到字符流的桥梁:它读入字节,并根据指定的编码方式,将之转换为字符流。使用的编码方式可能由名称指定,或平台可接受的缺省编码方式。

InputStreamReader 的 read() 方法之一的每次调用,可能促使从基本字节输入流中读取一个或多个字节。为了达到更高效率,考虑用 BufferedReader 封装 InputStreamReader,例如:

 BufferedReader in
   = new BufferedReader(new InputStreamReader(System.in));
 

来自:
JDK1.1
参见:
BufferedReader, InputStream

构造子索引

InputStreamReader(InputStream)
用缺省的字符编码方式,创建一个 InputStreamReader。
InputStreamReader(InputStream, String)
用已命名的字符编码方式,创建一个 InputStreamReader。

方法索引

close()
关闭流。
getEncoding()
返回当前流使用的编码方式名。
read()
读取单一字符。
read(char[], int, int)
将若干字符读入一个数组中。
ready()
报告此流是否已准备读。

构造子

InputStreamReader
 public InputStreamReader(InputStream in)
用缺省的字符编码方式,创建一个 InputStreamReader。

参数:
in - 一个 InputStream
InputStreamReader
 public InputStreamReader(InputStream in,
                          String enc) throws UnsupportedEncodingException
用已命名的字符编码方式,创建一个 InputStreamReader。

参数:
in - 一个 InputStream
enc - 使用的编码方式名
抛出: UnsupportedEncodingException
如果不支持名称编码

方法

getEncoding
 public String getEncoding()
返回当前流使用的编码方式名。 如果该流已关闭则返回 null。

read
 public int read() throws IOException
读取单一字符。

返回值:
读取的字符;如果已读到流尾则返回 -1。
抛出: IOException
如果发生一 I/O 错误。
覆盖:
Reader 中的 read
read
 public int read(char cbuf[],
                   int off,
                 int len) throws IOException
将若干字符读入一个数组中。

参数:
cbuf - 目的缓冲区
off - 开始存储字符的偏移量。
len - 读取的最大字符数
返回值:
读取的字符数;如果已读到流尾则返回 -1。
抛出: IOException
如果发生一 I/O 错误。
覆盖:
Reader 中的 read
ready
 public boolean ready() throws IOException
报告此流是否已准备读。 如果它的输入缓冲不空或有可读字节,则 InputStreamReader 读就绪。

抛出: IOException
如果发生一 I/O 错误。
覆盖:
Reader 中的 ready
close
 public void close() throws IOException
关闭流。

抛出: IOException
如果发生一 I/O 错误。
覆盖:
Reader 中的 close

当前位置 类层次(JDK) 所有类(JDK) 所有域和方法(JDK)