| 
JavaTM 2 Platform Standard Ed. 5.0  | 
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.io.Reader
java.io.InputStreamReader
public class InputStreamReader
InputStreamReader 是字节流通向字符流的桥梁:它使用指定的  读取字节并将其解码为字符。它使用的字符集可以由名称指定或显式给定,否则可能接受平台默认的字符集。
charset
每次调用 InputStreamReader 中的一个 read() 方法都会导致从基础输入流读取一个或多个字节。要启用从字节到字符的有效转换,可以提前从基础流读取更多的字节,使其超过满足当前读取操作所需的字节。
为了达到最高效率,可要考虑在 BufferedReader 内包装 InputStreamReader。例如:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedReader, 
InputStream, 
Charset| 字段摘要 | 
|---|
| 从类 java.io.Reader 继承的字段 | 
|---|
lock | 
| 构造方法摘要 | |
|---|---|
InputStreamReader(InputStream in)
创建一个使用默认字符集的 InputStreamReader。  | 
|
InputStreamReader(InputStream in,
                  java.nio.charset.Charset cs)
创建使用给定字符集的 InputStreamReader。  | 
|
InputStreamReader(InputStream in,
                  java.nio.charset.CharsetDecoder dec)
创建使用给定字符集解码器的 InputStreamReader。  | 
|
InputStreamReader(InputStream in,
                  String charsetName)
创建使用指定字符集的 InputStreamReader。  | 
|
| 方法摘要 | |
|---|---|
 void | 
close()
关闭该流。  | 
 String | 
getEncoding()
返回此流使用的字符编码的名称。  | 
 int | 
read()
读取单个字符。  | 
 int | 
read(char[] cbuf,
     int offset,
     int length)
将字符读入数组中的某一部分。  | 
 boolean | 
ready()
告知是否准备读取此流。  | 
| 从类 java.io.Reader 继承的方法 | 
|---|
mark, markSupported, read, read, reset, skip | 
| 从类 java.lang.Object 继承的方法 | 
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| 构造方法详细信息 | 
|---|
public InputStreamReader(InputStream in)
in - InputStream
public InputStreamReader(InputStream in,
                         String charsetName)
                  throws UnsupportedEncodingException
in - InputStreamcharsetName - 受支持的 charset 的名称
UnsupportedEncodingException - 如果不支持指定的字符集
public InputStreamReader(InputStream in,
                         java.nio.charset.Charset cs)
in - InputStreamcs - 字符集
public InputStreamReader(InputStream in,
                         java.nio.charset.CharsetDecoder dec)
in - InputStreamdec - 字符集解码器| 方法详细信息 | 
|---|
public String getEncoding()
如果该编码有历史上用过的名称,则返回该名称;否则返回该编码的规范化名称。
 如果使用 InputStreamReader(InputStream, String) 构造方法创建此实例,则返回的由此编码生成的唯一名称可能与传递给该构造方法的名称不一样。如果流已经关闭,则此方法可能返回 null。 
nullCharset
public int read()
         throws IOException
Reader 中的 readIOException - 如果发生 I/O 错误
public int read(char[] cbuf,
                int offset,
                int length)
         throws IOException
Reader 中的 readcbuf - 目标缓冲区offset - 以其处开始存储字符的偏移量length - 要读取的最大字符数
IOException - 如果发生 I/O 错误
public boolean ready()
              throws IOException
Reader 中的 readyIOException - 如果发生 I/O 错误
public void close()
           throws IOException
Closeable 中的 closeReader 中的 closeIOException - 如果发生 I/O 错误
  | 
JavaTM 2 Platform Standard Ed. 5.0  | 
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。