public class LineNumberReader extends BufferedReader
getLineNumber()
setLineNumber(int)用于设置和获取当前行数分别为。
默认情况下,行编号从0开始。这个数字在每一line terminator增量的数据读取,并可与电话setLineNumber(int)改变。但是请注意,这setLineNumber(int)实际上并没有改变流中的当前位置;它只改变值,将返回的getLineNumber()。
一条线是由一个换行的任何一个terminated('\n'),回车(“R”),或一个回车紧接着换行。
| Constructor and Description |
|---|
LineNumberReader(Reader in)
创建一个新的行编号读写器,使用默认的输入缓冲区大小。
|
LineNumberReader(Reader in, int sz)
创建一个新的行编号读写器,将字符转换为给定大小的缓冲区。
|
| Modifier and Type | Method and Description |
|---|---|
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)
跳过的字符。
|
close, lines, markSupported, readypublic LineNumberReader(Reader in)
in -读者对象提供基础流
public LineNumberReader(Reader in, int sz)
in -读者对象提供基础流
sz指定缓冲区大小的整数
public void setLineNumber(int lineNumber)
lineNumber指定行号int
getLineNumber()
public int getLineNumber()
setLineNumber(int)
public int read()
throws IOException
read 方法重写,继承类
BufferedReader
IOException如果I/O错误发生
public int read(char[] cbuf,
int off,
int len)
throws IOException
read 方法重写,继承类
BufferedReader
cbuf -目的缓冲区
off偏移,开始存储字符
len -最大字符数读
IOException如果I/O错误发生
public String readLine() throws IOException
readLine 方法重写,继承类
BufferedReader
IOException如果I/O错误发生
Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)
public long skip(long n)
throws IOException
skip 方法重写,继承类
BufferedReader
n -字符数跳过
IOException如果I/O错误发生
IllegalArgumentException -如果
n是负的
public void mark(int readAheadLimit)
throws IOException
mark 方法重写,继承类
BufferedReader
readAheadLimit的字符数限制,可同时仍保留了马克读。读了这许多字符后,试图重置流可能会失败。
IOException如果I/O错误发生
public void reset()
throws IOException
reset 方法重写,继承类
BufferedReader
IOException如果流不被标记,或者如果该商标已失效
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.