This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Does RandomAccessFile need a bufffer class?  RSS feed

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the case of reading from and writing to a text file, it is helpful to use a buffer class, so that the program stores up the data in a buffer before reading and writing, and does not have to open up the file on the hard disk every time a few characters are added to the file.
How about the case of RandomAccessFile? Is that automatically buffered, or is it helpful to chain it to a buffer class?
My guess is that it is automatically buffered if the mode is "rw" or "r", but not buffered if the mode is another mode.
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last time I looked into it, RandomAccessFile was not buffered. You can check the source yourself. Look in the JDK directory for a src.zip file.
This makes sense because if the access is truly random, how would it know which data to buffer? If it were aggressive in buffering the wrong data, it would actually perform worse than an unbuffered RAF.
That said, I've seen a couple of articles here and here on buffering RAF.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!