Difference between FileReader and BufferedReader in java file IO





In this post we will be discussing differences between FileReader  and BufferedReader





Difference between FileReader and BufferedReader in java file IO >


BufferedReader
FileReader
1

BufferedReader is buffered.
FileReader is not buffered.
2
3
when BufferedReader.read() is called mostly data is read from the buffer.

When data is not available available in buffer a call is made to read system file and lot of characters are kept in buffer.
Every time FileReader.read() is called a call is made to read a system file.

FileReader.read()
reads 2 byte (16-bit) at a time.
4
A BufferedReader enables another  Reader to buffer the characters and supports the mark and reset methods.
An internal buffer array is created when the BufferedReader is created.
As characters from the Reader are read or skipped, the internal buffer is refilled as necessary from the contained  Reader, many characters at a time.
A FileReader obtains  characters from a file in a file system.
And does not supports mark and reset methods.
5
BufferedReader is much faster as compared to FileReader.
FileReader is slower as compared to BufferedReader.
6
Example -
As we discussed above that when BufferedReader.read() is called mostly data is read from the buffer.
A BufferedReader reads from FileReader, will request lot of data from the FileReader (128 characters or so… not exact figure). Thus only 2 calls will be made for reading 256 characters from file.
Example -
As we discussed in point above that every time FileReader.read() is called a call is made to read a system file.

A FileReader will make 256 calls for reading 256 characters from file.

Another Example - Real world Example - You must have seen youtube videos where video is buffered before you actually start watching it, buffering overall improves your video watching experience.
No buffering will make your videos watching experience a nightmare.




RELATED LINKS>

Difference between FileInputStream and BufferedInputStream in java file IO


Difference between Stream (FileInputStream) and Reader (FileReader) in java file handling

Program to Create Directory - Single and multiple (i.e. parent and child directories) in java file IO

Create File using createNewFile() method in java file IO


eEdit
Must read for you :