I just found this
FileReader reader = new FileReader("SomePath");
char[] buf = new char[100];
reader.read(buf);
So why should I use BufferedReader if FileReader itself has a method to read more than 1 byte.
I just found this
FileReader reader = new FileReader("SomePath");
char[] buf = new char[100];
reader.read(buf);
So why should I use BufferedReader if FileReader itself has a method to read more than 1 byte.
Because the 100 character array you passed to the read(char[])
method is much smaller than the most efficient block size that can be read from the hard drive. The buffer allows you to make reads in sizes that are convenient to your code while still maintaining the optimal read size in the hardware layer.
What's the optimal read size for BufferedReader
then? It depends on the underlying data source. If you don't know it, use the default size.