Class BufferedReader
java.lang.Object
java.io.Reader
java.io.BufferedReader
- All Implemented Interfaces:
Closeable, AutoCloseable
Reads text from another reader through a buffer, and reads it a line at
a time. A line ends at \n, \r or \r\n.
Like most readers, it is for one thread at a time.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionBufferedReader(Reader in) Buffersinwith an 8192 character buffer.BufferedReader(Reader in, int size) Buffersinwith a buffer ofsizecharacters. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the stream.lines()The remaining lines, read as the stream asks for them.voidmark(int readAheadLimit) Mark the present position in the stream.booleanTell whether this stream supports the mark() operation.intread()Read a single character.intread(char[] cbuf, int off, int len) Read characters into a portion of an array.readLine()Reads a line of text, without its terminator.booleanready()Tell whether this stream is ready to be read.voidreset()Reset the stream.longskip(long n) Skip characters.Methods inherited from class Reader
read, transferTo
-
Constructor Details
-
BufferedReader
Buffersinwith an 8192 character buffer. -
BufferedReader
Buffers
inwith a buffer ofsizecharacters.Throws
IllegalArgumentException: whensizeis not positive
-
-
Method Details
-
read
Description copied from class:ReaderRead a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached. Subclasses that intend to support efficient single-character input should override this method.- Overrides:
readin classReader- Throws:
IOException
-
read
Description copied from class:ReaderRead characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.- Specified by:
readin classReader- Throws:
IOException
-
readLine
Reads a line of text, without its terminator.
Returns
the line, or null at the end of the text
- Throws:
IOException
-
ready
Description copied from class:ReaderTell whether this stream is ready to be read.- Overrides:
readyin classReader- Throws:
IOException
-
skip
Description copied from class:ReaderSkip characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.- Overrides:
skipin classReader- Throws:
IOException
-
markSupported
public boolean markSupported()Description copied from class:ReaderTell whether this stream supports the mark() operation. The default implementation always returns false. Subclasses should override this method.- Overrides:
markSupportedin classReader
-
mark
Description copied from class:ReaderMark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point. Not all character-input streams support the mark() operation.- Overrides:
markin classReader- Throws:
IOException
-
reset
Description copied from class:ReaderReset the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point. Not all character-input streams support the reset() operation, and some support reset() without supporting mark().- Overrides:
resetin classReader- Throws:
IOException
-
close
Description copied from class:ReaderClose the stream. Once a stream has been closed, further read(), ready(), mark(), or reset() invocations will throw an IOException. Closing a previously-closed stream, however, has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException
-
lines
-