What are the differences between BufferedReader
, BufferedInputStream
and Scanner
in java? BufferedReader
reads the text and BufferedInputStream
reads byte
. Is there any difference other than this?
BufferedReader reads a couple of characters from the Input Stream and stores them in a buffer. InputStreamReader reads only one character from the input stream and the remaining characters still remain in the streams hence There is no buffer in this case.
DataInputStream is a kind of InputStream to read data directly as primitive data types. BufferedInputStream is a kind of inputStream that reads data from a stream and uses a buffer to optimize speed access to data.
FileReader is used to read a file from a disk drive whereas BufferedReader is not bound to only reading files. It can be used to read data from any character stream.
A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the mark and reset methods. When the BufferedInputStream is created, an internal buffer array is created.
I guess, the difference is the same as between reader and inputstream: one is character-based, another is byte-based. For example, reader normally supports encoding...
Edit: Check this question: The difference between InputStream and InputStreamReader when reading multi-byte characters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With