GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||
GeezerVison is showing www.geeksforgeeks.org — Java.io.BufferedReader Class in Java - GeeksforGeeks Java.io.BufferedReader Class in JavaLast Updated : 6 Oct, 2026 The BufferedReader class in Java helps read text efficiently from files or user input. It stores data in a buffer, making reading faster and smoother instead of reading one character at a time.
Class Declaration
Sample.txt
The BufferedReader class extends the Reader class, which means it is a subclass specialized for character input with buffering capabilities.
Output: ![]() Explanation: The program uses BufferedReader with FileReader to read text line by line from the file sample.txt. The readLine() method continues until it reaches the end of the file (null). Constructor of BufferedReader Class1. BufferedReader(Reader in): Creates a buffered character input stream using the specified reader.
2. BufferedReader(Reader in, int size): Creates a buffered character input stream with a custom buffer size.
Example: Reading Text from a File
Output: ![]()
|
| Method | Action |
|---|---|
| close() | Closes the stream and releases associated resources. |
| mark(int readAheadLimit) | Marks the current position so that the stream can later be reset to this position. |
| markSupported() | Checks whether the stream supports the mark() operation. BufferedReader supports marking. |
| read() | Reads a single character and returns -1 when the end of the stream is reached. |
| read(char[] cbuf, int off, int len) | Reads characters into a portion of the specified character array. |
| readLine() | Reads a line of text and returns null when the end of the stream is reached. |
| ready() | Returns true if the stream is ready to be read without blocking. |
| reset() | Resets the stream to the most recent mark. |
| skip(long n) | Skips the specified number of characters. |
lines() | Returns a Stream<String> containing the lines read from the BufferedReader. |