← 返回首页
BufferedReader (Java SE 26 & JDK 26)
JavaScript is disabled on your browser.
Contents  
  1. Description
  2. Field Summary
  3. Constructor Summary
  4. Method Summary
    1. Methods declared in class Reader
    2. Methods declared in class Object
  5. Constructor Details
    1. BufferedReader(Reader, int)
    2. BufferedReader(Reader)
  6. Method Details
    1. read()
    2. read(char[], int, int)
    3. readLine()
    4. ready()
    5. markSupported()
    6. mark(int)
    7. reset()
    8. close()
    9. lines()
Hide sidebar  Show sidebar

Class BufferedReader

java.lang.Object
java.io.Reader
java.io.BufferedReader
All Implemented Interfaces: Closeable, AutoCloseable, Readable Direct Known Subclasses: LineNumberReader
public class BufferedReader extends Reader
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.

The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.

In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,

Copy BufferedReader in = new BufferedReader(new FileReader("foo.in"));
will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.

Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.

API Note: Once wrapped in a BufferedReader, the underlying Reader should not be used directly nor wrapped with another reader. Since: 1.1 See Also:

Scripting on this page tracks web page traffic, but does not change the content in any way.