• Post Reply Bookmark Topic Watch Topic
  • New Topic

BufferWriter class is faster compare to the Writer Class.What is the reason behind it

 
dev pandya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading that BufferWriter or Buffer Reader is faster compare to the Writer or reader class?Why??
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Disk storage is very slow compared to computer memory. Whenever a program has to ask a disk "please read me some data" or "please write this data on the disk", the program needs to wait a very long time before the operation is complete. Therefore it makes sense to ask the disk to do this things as infrequently as possible. The way to do that is to read as much as you can at one time, and write big chunks of data all at once.

This is called buffering, and that's what BufferedReader and BufferedWriter do. BufferedReader asks for more data than you request; it's betting that you're going to ask for more, later, and that's always a good bet. BufferedWriter stores the data you give to it until it collects a lot of data, then sends it to be written all in one big chunk.
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the IO Performance Chapter of Java Platform Performance for more on strategies on IO and how to measure performance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!