- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
When a constructor specifies a delimiter, and that delimiter is not
null, the method readLine()
will assume that an
end of line is represented by either a line feed, a carriage
return, or a carriage return followed by a line feed, with the
delimiter specifying which of these combinations represents the end
of a line. If the delimiter is null (the default), the behavior is
identical to that for BufferedReader
and any of
these will indicate an end of line. When a line feed or carriage
return does not denote an end of line, that line feed or carriage
return will be kept as part of the line.
The behavior for BufferedReader
is appropriate when
one is reading text files that may have been generated on systems
using differing, but common, end-of-line conventions. LineReader
with an explicit delimiter choice is useful when
processing files that conform to standards that specify specific
line-termination sequences, and where characters that are not part
of that sequence should be kept as is.
To specify a character encoding, the Reader
passed
as the first argument of a constructor should be an instance of
InputStreamReader
or a Reader
that
contains an instance of InputStreamReader
, possibly
with several intermediate readers.
-
Nested Class Summary
Nested Classes -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionLineReader
(Reader in) Constructor.LineReader
(Reader in, int sz) Constructor providing a buffer size.LineReader
(Reader in, int sz, LineReader.Delimiter delimiter) Constructor providing a buffer size and specifying the end-of-line character or sequence of characters.LineReader
(Reader in, LineReader.Delimiter delimiter) Constructor specifying the end-of-line character or sequence of characters. -
Method Summary
Methods inherited from class java.io.BufferedReader
close, lines, mark, markSupported, read, read, ready, reset, skip
Methods inherited from class java.io.Reader
nullReader, read, read, transferTo
-
Constructor Details
-
LineReader
Constructor. The default buffer size will be used.- Parameters:
in
- a Reader
-
LineReader
Constructor providing a buffer size.- Parameters:
in
- a Readersz
- the input-buffer size
-
LineReader
Constructor specifying the end-of-line character or sequence of characters. The default buffer size will be used.- Parameters:
in
- a Readerdelimiter
- the choice of delimiter (LineReader.Delimiter.LF
,LineReader.Delimiter.CR
,LineReader.Delimiter.CRLF
, or null for all of the these)
-
LineReader
Constructor providing a buffer size and specifying the end-of-line character or sequence of characters.- Parameters:
in
- a Readersz
- the input-buffer sizedelimiter
- the choice of delimiter (LineReader.Delimiter.LF
,LineReader.Delimiter.CR
,LineReader.Delimiter.CRLF
, or null for all of the these)
-
-
Method Details
-
readLine
Read a line of text. When the constructor provides a delimiter, that delimiter is the one that will be used, and the other end-of-line characters are treated as characters within the line. If the delimiter is null (the default), the behavior is identical to that forBufferedReader
.- Overrides:
readLine
in classBufferedReader
- Returns:
- a line of text; null if the end of the file has been reached
- Throws:
IOException
- an IO error occurred
-