• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Hu Yong Jun
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1st make the file longer my the required amount
 
Rob Shields
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic