java.io.BufferedReader
java.io.Reader
None
None
New as of JDK 1.1
A BufferedReader object provides a more efficient way to read just a few characters at a time from a Reader. BufferedReader objects use a buffer to store input from an associated Reader. In other words, a large number of characters are read from the underlying reader and stored in an internal buffer. A BufferedReader is more efficient than a regular Reader because reading data from memory is faster than reading it from a disk or a network. All reading is done directly from the buffer; the disk or network needs to be accessed only occasionally to fill up the buffer.
You should wrap a BufferedReader around any Reader whose read() operations may be time consuming or costly, such as a FileReader or InputStreamReader.
BufferedReader provides a way to mark a position in the stream and subsequently reset the stream to that position, using mark() and reset().
A BufferedReader is similar to a BufferedInputStream, but it operates on a stream of Java characters instead of a byte stream, which makes it easier to support internationalization.
public class java.io.BufferedReader extends java.io.Reader { // Constructors public BufferedReader(Reader in); public BufferedReader(Reader in, int sz); // Instance Methods public void close(); public void mark(int readAheadLimit); public boolean markSupported(); public int read(); public int read(char[] cbuf, int off, int len); public String readLine(); public boolean ready(); public void reset(); public long skip(long n); }
The reader to buffer.
This constructor creates a BufferedReader that buffers input from the given Reader using a buffer with the default size of 8192 characters.
The reader to buffer.
The size of buffer to use.
If the specified size is less than 0.
This constructor creates a BufferedReader that buffers input from the given Reader, using a buffer of the given size.
If any kind of I/O error occurs.
Reader.close()
This method closes this BufferedReader and its underlying Reader.
The maximum number of bytes that can be read before the saved position becomes invalid.
If the stream is closed.
Reader.mark(int)
This method causes the BufferedReader to remember its current position. A subsequent call to reset() causes the object to return to that saved position, and thus reread a portion of the buffer.
The boolean value true.
Reader.markSupported()
This method returns true to indicate that this class supports mark() and reset().
The next character of data, or -1 if the end of the stream is encountered.
If any kind of I/O error occurs.
Reader.read()
This method returns the next character from the buffer. If all the characters in the buffer have been read, the buffer is filled from the underlying Reader, and the next character is returned. If the buffer does not need to be filled, this method returns immediately. If the buffer needs to be filled, this method blocks until data is available from the underlying Reader, the end of the stream is reached, or an exception is thrown.
An array of characters to be filled from the stream.
Offset into the character array.
Number of characters to read.
The actual number of characters read or -1 if the end of the stream is encountered immediately.
If any kind of I/O error occurs.
Reader.read(char[], int, int)
This method reads characters from the internal buffer into the given array cbuf, starting at index off and continuing for up to len bytes. If there are any characters in the buffer, this method returns immediately. Otherwise the buffer needs to be filled; this method blocks until the data is available from the underlying InputStream, the end of the stream is reached, or an exception is thrown.
A String containing the line just read, or null if the end of the stream has been reached.
If any kind of I/O error occurs.
This method reads a line of text. Lines are terminated by "\n", "\r", or "\r\n". The line terminators are not returned with the line string.
A boolean value that indicates whether the stream is ready to be read.
If the stream is closed.
Reader.ready()
If there is data in the buffer, or if the underlying stream is ready, this method returns true. The underlying stream is ready if the next read() is guaranteed to not block. Note that a return value of false does not guarantee that the next read operation will block.
If the reader is closed, mark() has not been called, or the saved position has been invalidated.
Reader.reset()
This method sets the position of the BufferedReader to a position that was saved by a previous call to mark(). Subsequent characters read from this BufferedReader will begin from the saved position and continue normally.
The number of characters to skip.
The actual number of characters skipped.
If any kind of I/O error occurs.
Reader.skip()
This method skips n characters of input. If the new position of the stream is still within the data contained in the buffer, the method returns immediately. Otherwise the buffer is repeatedly filled until the requested position is available.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
read(char[]) |
Reader |
toString() |
Object |
void wait() |
Object |
void wait(long) |
Object |
void wait(long, int) |
Object |
IllegalArgumentException, IOException, Reader, String