Question regarding the buffer created with BufferedReader class
Moieen Khatri
Ranch Hand
Joined: Nov 27, 2007
Posts: 144
posted
0
Hi,
Can some please let me know what exactly is the buffer which is created using the BufferedReader class? Is all the data read into the Buffer first before writing data to the file? What is the advantage of this buffering and why is it requried?
Thanks, Moieen
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35257
7
posted
0
Welcome to JavaRanch.
The Javadocs of BufferedReader and BufferedWriter mention the benefits of using them, and what the buffer is and does; basically, it can be good for performance. As such, it's optional to use buffers, but not required.
Basically, I/O buffering (at least for disk media) reduces the number of number of physical seek/read/write operations that have to be performed, which usually leads to a significant increase in performance.
You can tell BufferedReader to use a specific buffer size by passing the size to its constructor. Otherwise, it will use an implementation-specific default value (a typical value would be something like 8192 bytes). If your file is no larger than the buffer size, then the entire file will indeed be read into memory all at once.
SCJP 5.0
Moieen Khatri
Ranch Hand
Joined: Nov 27, 2007
Posts: 144
posted
0
thanks for the help guys.... I am clear about this concept now