What is the difference between Java's BufferedReader and InputStreamReader classes?

Ajay Yadav picture Ajay Yadav · Sep 11, 2011 · Viewed 54.7k times · Source

What is the difference between Java's BufferedReader and InputStreamReader classes?

Answer

amod picture amod · Sep 11, 2011

BufferedReader is a wrapper for both "InputStreamReader/FileReader", which buffers the information each time a native I/O is called.

You can imagine the efficiency difference with reading a character(or bytes) vis-a-vis reading a large no. of characters in one go(or bytes). With BufferedReader, if you wish to read single character, it will store the contents to fill its buffer (if it is empty) and for further requests, characters will directly be read from buffer, and hence achieves greater efficiency.

InputStreamReader converts byte streams to character streams. It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

Hope it helps.