aspose file tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How can I write a new record at the end of random access file of database? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "How can I write a new record at the end of random access file of database?" Watch "How can I write a new record at the end of random access file of database?" New topic
Author

How can I write a new record at the end of random access file of database?

Hu Yong Jun
Greenhorn

Joined: Jun 20, 2003
Posts: 26
The test method throws an EOFException when I test the Data.create() method.

How can append record to the random access file?
mike acre
Ranch Hand

Joined: Sep 23, 2003
Posts: 197
1st make the file longer my the required amount


SCJP 1.4, SCJD
Rob Shields
Greenhorn

Joined: Oct 11, 2004
Posts: 19
Hi

Writing beyond the end of the file should cause the file to be automatically extended without this exception being thrown.

Are you sure you're not trying read beyond the end of the file, because that would cause EOFException to be thrown.

Rob
Rob Shields
Greenhorn

Joined: Oct 11, 2004
Posts: 19
From the Javadoc:

Output operations that write past the current end of the implied array cause the array to be extended...

It is generally true of all the reading routines in this class that if end-of-file is reached before the desired number of bytes has been read, an EOFException (which is a kind of IOException) is thrown. ...


seek():
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.
mike acre
Ranch Hand

Joined: Sep 23, 2003
Posts: 197
Despite my ignorance of this fact, it is perhaps a good idea to explicitly extend the length from a self documenting perspective.
Hu Yong Jun
Greenhorn

Joined: Jun 20, 2003
Posts: 26
Thank you all.

Before really writing I have a read statement to check if the record with that recNo exists and is already created by other. It is this statement that throws the EOFException.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How can I write a new record at the end of random access file of database?
 
Similar Threads
Create()
DB File Insert Values
Take this Testing Tool for Data Class
RandomAccessFile.length() is not thread save!
Unit testing on multi-threads access to one database