In this post we will be discussing differences between FileReader and BufferedReader
Difference between FileReader and BufferedReader in java file IO >
BufferedReader is buffered.
FileReader is not buffered.
BufferedReader reads characters from another Reader (Eg - FileReader)
FileReader reads characters from a file.
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.
reads 2 byte (16-bit) at a time.
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.
BufferedReader is much faster as compared to FileReader.
FileReader is slower as compared to BufferedReader.
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.
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.