This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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: 24217
38
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: 9425
12
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!