This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create()

 
GD Deepz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably a simple question. How do I append data to a Random Access File? For a brand new record I want to add the record to the end of the file BUT I cannot add more data pass the length of the record.

I seek the last valid record, go to the end of it and then add the new record but I cannot do this because I am going past the length of the file.

If there is a deleted rec, that I will use that position but if there are no deleted records, then I have append a new record to end of the file

Tks
 
Matt Sheehan.
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, you can write past the end of the file without problems. From the API:
A random access file behaves like a large array of bytes stored in the file system....Output operations that write past the current end of the implied array cause the array to be extended.

My implementation would seek to a record and write whether or not it was reused or new. If you try to read past the end of the file, though, you will get an Exception.

HTH, Matt
 
GD Deepz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I can append data at the end of a RAF file, how am I going to read that same data later if an IOException is thrown
 
Matt Sheehan.
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Writing past the file extends the length of the file. Therefore, if you append a new record, it is considered part of the file and can be read without an Exception.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic