Most visited

Recently visited

Added in API level 1

LineNumberReader

public class LineNumberReader
extends BufferedReader

java.lang.Object
   ↳ java.io.Reader
     ↳ java.io.BufferedReader
       ↳ java.io.LineNumberReader


一个缓冲的字符输入流,用于跟踪行号。 该类定义getLineNumber()用于设置和获取当前行号的方法setLineNumber(int)getLineNumber()

默认情况下,行编号从0开始。随着数据被读取,此编号每line terminator递增,并且可以通过调用setLineNumber(int)更改 但请注意, setLineNumber(int)实际上并未更改流中的当前位置; 它只会更改将由getLineNumber()返回的

换行符('\ n'),回车符('\ r')或回车符后面的换行符被视为 terminated

Summary

Inherited fields

From class java.io.Reader

Public constructors

LineNumberReader(Reader in)

使用默认的输入缓冲区大小创建一个新的行编号阅读器。

LineNumberReader(Reader in, int sz)

创建一个新的行号读取器,将字符读入给定大小的缓冲区。

Public methods

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)

跳过字符。

Inherited methods

From class java.io.BufferedReader
From class java.io.Reader
From class java.lang.Object
From interface java.lang.Readable
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public constructors

LineNumberReader

Added in API level 1
LineNumberReader (Reader in)

使用默认的输入缓冲区大小创建一个新的行编号阅读器。

Parameters
in Reader: A Reader object to provide the underlying stream

LineNumberReader

Added in API level 1
LineNumberReader (Reader in, 
                int sz)

创建一个新的行号读取器,将字符读入给定大小的缓冲区。

Parameters
in Reader: A Reader object to provide the underlying stream
sz int: An int specifying the size of the buffer

Public methods

getLineNumber

Added in API level 1
int getLineNumber ()

获取当前行号。

Returns
int The current line number

也可以看看:

mark

Added in API level 1
void mark (int readAheadLimit)

标记流中的当前位置。 之后对reset()的调用将尝试将流重新定位到该点,并且还会适当地重置行号。

Parameters
readAheadLimit int: Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail.
Throws
IOException If an I/O error occurs

read

Added in API level 1
int read ()

阅读一个字符。 Line terminators被压缩成单个换行符('\ n')字符。 无论何时读取行终止符,当前行号都会递增。

Returns
int The character read, or -1 if the end of the stream has been reached
Throws
IOException If an I/O error occurs

read

Added in API level 1
int read (char[] cbuf, 
                int off, 
                int len)

将字符读入数组的一部分。 无论何时读取line terminator ,当前行号都会增加。

Parameters
cbuf char: Destination buffer
off int: Offset at which to start storing characters
len int: Maximum number of characters to read
Returns
int The number of bytes read, or -1 if the end of the stream has already been reached
Throws
IOException If an I/O error occurs

readLine

Added in API level 1
String readLine ()

阅读一行文字。 无论何时读取line terminator ,当前行号都会增加。

Returns
String A String containing the contents of the line, not including any line termination characters, or null if the end of the stream has been reached
Throws
IOException If an I/O error occurs

reset

Added in API level 1
void reset ()

将流重置为最近的标记。

Throws
IOException If the stream has not been marked, or if the mark has been invalidated

setLineNumber

Added in API level 1
void setLineNumber (int lineNumber)

设置当前行号。

Parameters
lineNumber int: An int specifying the line number

也可以看看:

skip

Added in API level 1
long skip (long n)

跳过字符。

Parameters
n long: The number of characters to skip
Returns
long The number of characters actually skipped
Throws
IOException If an I/O error occurs
IllegalArgumentException If n is negative

Hooray!