Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Does RandomAccessFile need a bufffer class?  RSS feed

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.
Posts: 9521
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 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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!