Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why use RandomAccessFile  RSS feed

 
Calvin Yan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you tell the reason of using RandomAccessFile? Why it's better when I want to append some content to a file?
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you tell the reason of using RandomAccessFile?

Sometimes stream-based access just doesn't cut it. For example, if you were implementing a database you might have a table represented as a file with fixed-width records. The ability to change properties of that record in place without opening an OutputStream and rewriting the entire file from scratch is very significant.

Why it's better when I want to append some content to a file?

It's not.
 
Calvin Yan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you David. I've just read the API documents again and see what you mean. File Pointer makes things more efficient and easy in some certain situations
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!