BufferedReader class provides buffering to your
can speed up IO quite a bit. Rather than read one character at a time from the network or disk, you
read a larger block at a time. This is typically much faster, especially for disk access and larger
The main difference between
Reader's work on characters (text), wheres
on raw bytes.
To add buffering to your
Reader's simply wrap them in a
Here is how that looks:
Reader input = new BufferedReader( new FileReader("c:\\data\\input-file.txt"));
Simple, isn't it? You can set the buffer size to use internally by the
You provide the size as a constructor parameter, like this:
Reader input = new BufferedReader( new FileReader("c:\\data\\input-file.txt"), 8 * 1024 );
This example sets the internal buffer to 8 KB. It is best to use buffer sizes that are multiples of 1024 bytes. That works best with most built-in buffering in hard disks etc.
Except for adding buffering to your
BufferedReader behaves pretty much
Reader. It has one extra method though, the
readLine() method. This
method can be handy if you need to read input one line at a time.