java.lang.Objectjava.io.Reader
java.io.FilterReader
java.io.PushbackReader
public class PushbackReader
允许将字符推回到流的字符流 reader。
| 字段摘要 |
|---|
| 从类 java.io.FilterReader 继承的字段 |
|---|
in |
| 从类 java.io.Reader 继承的字段 |
|---|
lock |
| 构造方法摘要 | |
|---|---|
PushbackReader(Reader in) 创建具有单字符推回缓冲区的新推回 reader。 |
|
PushbackReader(Reader in, int size) 创建具有给定大小推回缓冲区的新推回 reader。 |
|
| 方法摘要 | |
|---|---|
void |
close() 关闭该流并释放与之关联的所有系统资源。 |
void |
mark(int readAheadLimit) 标记流中的当前位置。 |
boolean |
markSupported() 判断此流是否支持 mark() 操作(它一定不支持)。 |
int |
read() 读取单个字符。 |
int |
read(char[] cbuf, int off, int len) 将字符读入数组的某一部分。 |
boolean |
ready() 判断是否准备读取此流。 |
void |
reset() 重置该流。 |
long |
skip(long n) 跳过字符。 |
void |
unread(char[] cbuf) 推回一个字符数组,方法是将其复制到推回缓冲区前面。 |
void |
unread(char[] cbuf, int off, int len) 推回字符数组的某一部分,方法是将其复制到推回缓冲区的前面。 |
void |
unread(int c) 推回单个字符:将其复制到推回缓冲区的前面。 |
| 从类 java.io.Reader 继承的方法 |
|---|
read, read |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public PushbackReader(Reader in, int size)
in - 将从中读取字符的 reader
size - 推回缓冲区的大小
IllegalArgumentException - 如果 size <= 0
public PushbackReader(Reader in)
in - 将从中读取字符的 reader
| 方法详细信息 |
|---|
public int read()
throws IOException
FilterReader 中的
read
IOException - 如果发生 I/O 错误
public int read(char[] cbuf,
int off,
int len)
throws IOException
FilterReader 中的
read
cbuf - 目标缓冲区
off - 开始写入字符处的偏移量
len - 要读取的最多字符数
IOException - 如果发生 I/O 错误
public void unread(int c)
throws IOException
(char)c。
c - int 值,表示要被推回的字符
IOException - 如果推回缓冲区已满,或者发生一些其他 I/O 错误
public void unread(char[] cbuf,
int off,
int len)
throws IOException
cbuf[off],其后的字节将具有值
cbuf[off+1],依次类推。
cbuf - 字符数组
off - 要推回的第一个字符的偏移量
len - 要推回的字符数
IOException - 如果推回缓冲区中没有足够的空间,或者发生一些其他 I/O 错误
public void unread(char[] cbuf)
throws IOException
cbuf[0],其后的字节将具有值
cbuf[1],依次类推。
cbuf - 要推回的字符数组
IOException - 如果推回缓冲区中没有足够的空间,或者发生一些其他 I/O 错误
public boolean ready()
throws IOException
FilterReader 中的
ready
IOException - 如果发生 I/O 错误
public void mark(int readAheadLimit)
throws IOException
PushbackReader 的
mark 始终抛出异常。
FilterReader 中的
mark
readAheadLimit - 在仍保留该标记的情况下,对可读取字符数量的限制。在读取这样多的字符后,尝试重置流可能会失败。
IOException - 始终抛出,原因是不支持标记功能
public void reset()
throws IOException
PushbackReader 的
reset 方法始终抛出异常。
FilterReader 中的
reset
IOException - 始终抛出,原因是不支持重置功能
public boolean markSupported()
FilterReader 中的
markSupported
public void close()
throws IOException
Closeable 中的
close
FilterReader 中的
close
IOException - 如果发生 I/O 错误
public long skip(long n)
throws IOException
FilterReader 中的
skip
n - 要跳过的字符数
IllegalArgumentException - 如果
n 为负。
IOException - 如果发生 I/O 错误