|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
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,
Charset cs)
創建使用給定字元集的 InputStreamReader。 |
|
InputStreamReader(InputStream in,
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,
Charset cs)
in - InputStreamcs - 字元集
public InputStreamReader(InputStream in,
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
Reader 複製的描述
Closeable 中的 closeReader 中的 closeIOException - 如果發生 I/O 錯誤
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。