Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RandomAccessFile - overwrite or insert?  RSS feed

 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would be grateful if someone who has done this sort of work could clarify something for me. I want to use RandomAccessFile to insert new data values into an existing file. If I use something like raf.writeShort() can you tell me whether it will overwrite the existing data at the current byte position, or will it insert new data between existing values? (The first is what I want to do as these will be updates).
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overwrite. RandomAccessFiles work like large binary arrays. When you write data at a particular position, it replaces the current values. In order to insert a value, you need to increase the size of the file, shift values past the insertion point down, then write the inserted value.
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe, that's good news
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!