|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.io.Reader
java.io.BufferedReader
java.io.LineNumberReader
public class LineNumberReader
跟踪行号的缓冲字符输入流。此类定义了方法 setLineNumber(int) 和 getLineNumber(),它们可分别用于设置和获取当前行号。
默认情况下,行编号从 0 开始。该行号随数据读取在每个行结束符处递增,并且可以通过调用 setLineNumber(int) 更改行号。但要注意的是,setLineNumber(int) 不会实际更改流中的当前位置;它只更改将由 getLineNumber() 返回的值。
可认为行在遇到以下符号之一时结束:换行符('\n')、回车符('\r')、回车后紧跟换行符。
| 字段摘要 |
|---|
| 从类 java.io.Reader 继承的字段 |
|---|
lock |
| 构造方法摘要 | |
|---|---|
LineNumberReader(Reader in)
使用默认输入缓冲区的大小创建新的行编号 reader。 |
|
LineNumberReader(Reader in,
int sz)
创建新的行编号 reader,将字符读入给定大小的缓冲区。 |
|
| 方法摘要 | |
|---|---|
int |
getLineNumber()
获得当前行号。 |
void |
mark(int readAheadLimit)
标记该流中的当前位置。 |
int |
read()
读取单个字符。 |
int |
read(char[] cbuf,
int off,
int len)
将字符读入数组中的某一部分。 |
String |
readLine()
读取文本行。 |
void |
reset()
将该流重新设置为最新的标记。 |
void |
setLineNumber(int lineNumber)
设置当前行号。 |
long |
skip(long n)
跳过字符。 |
| 从类 java.io.BufferedReader 继承的方法 |
|---|
close, markSupported, ready |
| 从类 java.io.Reader 继承的方法 |
|---|
read, read |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public LineNumberReader(Reader in)
in - 提供底层流的 Reader 对象
public LineNumberReader(Reader in,
int sz)
in - 提供底层流的 Reader 对象sz - 指定缓冲区大小的 int 值| 方法详细信息 |
|---|
public void setLineNumber(int lineNumber)
lineNumber - 指定行号的 int 值getLineNumber()public int getLineNumber()
setLineNumber(int)
public int read()
throws IOException
BufferedReader 中的 readIOException - 如果发生 I/O 错误
public int read(char[] cbuf,
int off,
int len)
throws IOException
BufferedReader 中的 readcbuf - 目标缓冲区off - 开始存储字符处的偏移量len - 要读取的最多字符数
IOException - 如果发生 I/O 错误
public String readLine()
throws IOException
BufferedReader 中的 readLineIOException - 如果发生 I/O 错误
public long skip(long n)
throws IOException
BufferedReader 中的 skipn - 要跳过的字符数
IOException - 如果发生 I/O 错误
IllegalArgumentException - 如果 n 为负
public void mark(int readAheadLimit)
throws IOException
BufferedReader 中的 markreadAheadLimit - 在仍保留该标记的情况下,对可读取字符数量的限制。在读取这样多的字符后,尝试重置流可能会失败。
IOException - 如果发生 I/O 错误
public void reset()
throws IOException
BufferedReader 中的 resetIOException - 如果该流未被标记,或者该标记已失效
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。