File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Create() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Create()" Watch "Create()" New topic
Author

Create()

GD Deepz
Ranch Hand

Joined: Sep 29, 2004
Posts: 55
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

Joined: Oct 08, 2004
Posts: 63
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

Joined: Sep 29, 2004
Posts: 55
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

Joined: Oct 08, 2004
Posts: 63
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create()