• Post Reply Bookmark Topic Watch Topic
  • New Topic

using RandomAccessFile  RSS feed

 
Yu Sun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

When we use RandomAccessFile to read or write to the database file, can we simply pass the initial header information in the file and go to the data section directly.

For example, databaseFile.seek(70). And then iterate each record. The value of the location is precalculated.

Thanks.

Yu
 
David Byron
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. You can either read the header info dynamically (as Roel did) or hard code the values (as Roberto did). (I hope I remembered that correctly!)

Either way, one benefit of the RandomAccessFile is that you can bypass what isn't interesting and go directly to the records. Going to a given record by its number will prove quite convenient.
 
Yu Sun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David. I will go the simple way (as Roberto did)
 
Roberto Perillo
Bartender
Posts: 2273
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yu Sun wrote:I will go the simple way (as Roberto did)


You are a smart guy, champion!
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Byron wrote:(I hope I remembered that correctly!)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!