Class: java.io.LineNumberReader
- public class LineNumberReader
- extends BufferedReader
A buffered character-input stream that keeps track of line numbers. This
class defines methods java.io.LineNumberReader.setLineNumber(int) and java.io.LineNumberReader.getLineNumber() for setting and getting the current line number
respectively.
By default, line numbering begins at 0. This number increments at every line terminator as the data is read, and can be changed with a call to setLineNumber(int). Note however, that setLineNumber(int) does not actually change the current position in the stream; it only changes the value that will be returned by getLineNumber().
A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
Inheritance
Superclass tree:- java.lang.Object
- java.io.Reader
- java.io.BufferedReader
- java.io.LineNumberReader
Methods
-
LineNumberReadertop
public LineNumberReader(Reader in)Create a new line-numbering reader, using the default input-buffer size. -
LineNumberReadertop
public LineNumberReader(Reader in, int sz)Create a new line-numbering reader, reading characters into a buffer of the given size. -
getLineNumbertop
public int getLineNumber()Get the current line number. -
marktop
public void mark(int readAheadLimit) throws IOExceptionMark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point, and will also reset the line number appropriately.- Override hierarchy:
- mark from BufferedReader
- mark from Reader
-
readtop
public int read() throws IOExceptionRead a single character. Line terminators are compressed into single newline ('\n') characters. Whenever a line terminator is read the current line number is incremented.- Override hierarchy:
- read from BufferedReader
- read from Reader
-
readtop
public int read(char[] cbuf, int off, int len) throws IOExceptionRead characters into a portion of an array. Whenever a line terminator is read the current line number is incremented.- Override hierarchy:
- read from BufferedReader
- read from Reader
-
readLinetop
public String readLine() throws IOExceptionRead a line of text. Whenever a line terminator is read the current line number is incremented.- Override hierarchy:
- readLine from BufferedReader
-
resettop
public void reset() throws IOExceptionReset the stream to the most recent mark.- Override hierarchy:
- reset from BufferedReader
- reset from Reader
-
setLineNumbertop
public void setLineNumber(int lineNumber)Set the current line number. -
skiptop
public long skip(long n) throws IOExceptionSkip characters.- Override hierarchy:
- skip from BufferedReader
- skip from Reader
