該類實(shí)現(xiàn)能用來作為字符輸入流的字符緩沖區(qū)。
類 java.io.CharArrayReader
類 java.io.CharArrayReader
java.lang.Object
|
+----java.io.Reader
|
+----java.io.CharArrayReader
- public class CharArrayReader
- extends Reader
變量索引
- buf
- 字符緩沖區(qū)
- count
- 緩沖區(qū)中合法字符數(shù)
- markedPos
- 緩沖區(qū)中標(biāo)記位置
- pos
- 當(dāng)前緩沖區(qū)位置
構(gòu)造子索引
- CharArrayReader(char[])
- 用指定字符數(shù)組創(chuàng)建一個(gè) CharArrayReader。
- CharArrayReader(char[], int, int)
- 用指定字符數(shù)組創(chuàng)建一個(gè) CharArrayReader。
方法索引
- close()
- 關(guān)閉流。
- mark(int)
- 標(biāo)記此流的。
- markSupported()
- 報(bào)告此流是否支持 mark() 實(shí)現(xiàn)的操作。
- read()
- 讀取單個(gè)字符。
- read(char[], int, int)
- 將字符讀入數(shù)組某部分中。
- ready()
- 報(bào)告此流是否已讀就緒。
- reset()
- 將流重置到最近標(biāo)記,若流從未標(biāo)記過,則復(fù)位到開始處。
- skip(long)
- 跳過若干字符。
變量
buf
protected char buf[]
- 字符緩沖區(qū)
pos
protected int pos
- 當(dāng)前緩沖區(qū)位置
markedPos
protected int markedPos
- 緩沖區(qū)中標(biāo)記位置
count
protected int count
- 緩沖區(qū)中合法字符數(shù)
構(gòu)造子
CharArrayReader
public CharArrayReader(char buf[])
- 用指定字符數(shù)組創(chuàng)建一個(gè) CharArrayReader。
- 參數(shù):
- buf - 輸入緩沖區(qū) (非復(fù)制的)
CharArrayReader
public CharArrayReader(char buf[],
int offset,
int length)
- 用特定字符數(shù)組創(chuàng)建一個(gè) CharArrayReader。
- 參數(shù):
- buf - 輸入緩沖區(qū) (非復(fù)制的)
- offset - 待讀取的首字符偏移量
- length - 待讀取的字符數(shù)。
方法
read
public int read() throws IOException
- 讀取單個(gè)字符。
- 拋出:
IOException
- 如果發(fā)生一 I/O 錯(cuò)誤。
- 覆蓋:
- 類
Reader 中的 read 。
read
public int read(char b[],
int off,
int len) throws IOException
- 將字符讀入數(shù)組某部分中。
- 參數(shù):
- b - 目標(biāo)緩沖區(qū)。
- off - 開始存儲(chǔ)字符的偏移量。
- len - 讀取的最大字符數(shù)
- 返回值:
- 實(shí)際讀取的字符數(shù),若已讀到流尾則返回 -1。
- 拋出:
IOException
- 如果發(fā)生一 I/O 錯(cuò)誤。
- 覆蓋:
- 類
Reader 中的
read 。
skip
public long skip(long n) throws IOException
- 跳過若干字符。
- 參數(shù):
- n - 待跳過的字節(jié)數(shù)
- 返回值:
- 實(shí)際跳過的字符數(shù)
- 拋出:
IOException
- 如果發(fā)生一 I/O 錯(cuò)誤。
- 覆蓋:
- 類
Reader 中的
skip 。
ready
public boolean ready() throws IOException
- 報(bào)告此流是否讀就緒。字符數(shù)組閱讀器總是讀就緒。
- 拋出:
IOException
- 如果發(fā)生一 I/O 錯(cuò)誤。
- 覆蓋:
- 類
Reader 中的
ready 。
markSupported
public boolean markSupported()
- 報(bào)告此流是否支持 mark() 實(shí)現(xiàn)的操作。
- 覆蓋:
- 類
Reader
中的
markSupported
mark
public void mark(int readAheadLimit) throws IOException
- 標(biāo)記此流的。后續(xù)調(diào)用 reset() 方法,重新將流定位到當(dāng)前點(diǎn)。
- 參數(shù):
- readAheadLimit - 保持標(biāo)記不變時(shí),讀取的字符數(shù)的限制。因?yàn)榱鞯妮斎雭碜杂谝粋€(gè)字符數(shù)組并無實(shí)際限制,所以可忽略該參數(shù)。
- 拋出:
IOException
- 如果發(fā)生一 I/O 錯(cuò)誤。
- 覆蓋:
- 類
Reader 中的 mark
reset
public void reset() throws IOException
- 將流重置到最近標(biāo)記,若流從未標(biāo)記過,則重置到開始處。
- 拋出:
IOException
- 如果發(fā)生一 I/O 錯(cuò)誤。
- 覆蓋:
- 類
Reader 中的 reset
close
public void close()
- 關(guān)閉流。
- 覆蓋:
- 類
Reader 中的 close