public class InputStreamReader extends Reader
charset将其解码为字符 。
它使用的字符集可以由名称指定,也可以被明确指定,或者可以接受平台的默认字符集。
每个调用InputStreamReader的read()方法之一可能会导致从底层字节输入流读取一个或多个字节。 为了使字节有效地转换为字符,可以从底层流读取比满足当前读取操作所需的更多字节。
为了最大的效率,请考虑在BufferedReader中包装一个InputStreamReader。 例如:
BufferedReader in
= new BufferedReader(new InputStreamReader(System.in));
BufferedReader , InputStream , Charset
| Constructor and Description |
|---|
InputStreamReader(InputStream in)
创建一个使用默认字符集的InputStreamReader。
|
InputStreamReader(InputStream in, Charset cs)
创建一个使用给定字符集的InputStreamReader。
|
InputStreamReader(InputStream in, CharsetDecoder dec)
创建一个使用给定字符集解码器的InputStreamReader。
|
InputStreamReader(InputStream in, String charsetName)
创建一个使用命名字符集的InputStreamReader。
|
public InputStreamReader(InputStream in)
in - 一个InputStream
public InputStreamReader(InputStream in, String charsetName) throws UnsupportedEncodingException
in - 一个InputStream
charsetName -的名字支持charset
UnsupportedEncodingException - 如果不支持命名的字符集
public InputStreamReader(InputStream in, Charset cs)
in - 一个InputStream
cs - 一个字符集
public InputStreamReader(InputStream in, CharsetDecoder dec)
in - 一个InputStream
dec - 一个字符集解码器
public String getEncoding()
如果编码具有历史名称,则返回该名称; 否则返回编码的规范名称。
如果此实例是使用InputStreamReader(InputStream, String)构造函数创建的,则返回的名称对于编码而言是唯一的,可能与传递给构造函数的名称不同。 如果流已关闭,此方法将返回null 。
null
Charset
public int read()
throws IOException
read在类
Reader
IOException - 如果发生I / O错误
public int read(char[] cbuf,
int offset,
int length)
throws IOException
read在
Reader
cbuf - 目的缓冲区
offset - 开始存储字符的偏移量
length - 要读取的最大字符数
IOException - 如果发生I / O错误
public boolean ready()
throws IOException
ready在
Reader类
IOException - 如果发生I / O错误
public void close()
throws IOException
Reader
close在接口
Closeable
close在接口
AutoCloseable
close在
Reader类
IOException - 如果发生I / O错误
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.