Reading Characters with read() in BufferedReader
You'll learn how to use read() methods in BufferedReader to efficiently read individual characters or fill character arrays using the internal buffer.
While readLine() is convenient for line-oriented reading, BufferedReader also provides read() methods inherited from Reader — but with an important difference: these methods benefit from internal buffering, making them far more efficient than calling read() directly on a FileReader.
Core read() Methods
BufferedReader offers the same read() methods you've seen in Reader:
read()– Returns a single character as anint(0-65535), or-1if end-of-stream is reachedread(char[] buffer)– Fills the provided character array, returns the number of characters actually readread(char[] buffer, int offset, int length)– Fills a portion of the array starting atoffsetfor up tolengthcharacters
Why Buffering Matters Here
Without buffering, each read() call would trigger a system call to fetch data from disk. BufferedReader pre-loads chunks of characters into an internal buffer (typically 8KB), so multiple read() calls pull from memory instead — drastically reducing I/O overhead.
Example Pattern
BufferedReader reader = new BufferedReader(new FileReader("data.txt"));
int ch;
while ((ch = reader.read()) != -1) {
System.out.print((char) ch);
}
reader.close();
Or with a character array for even better performance:
char[] buffer = new char[1024];
int charsRead;
while ((charsRead = reader.read(buffer)) != -1) {
System.out.print(new String(buffer, 0, charsRead));
}
Key Takeaway: BufferedReader's read() methods provide the same character-reading API as Reader, but with buffered performance — ideal when you need character-level control without line-based parsing.