Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question regarding the buffer created with BufferedReader class

 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help guys.... I am clear about this concept now

Cheers,
Moieen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic