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

Updating a file without overwriting the previous data  RSS feed

 
Maselo Snazz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a file that was written using DataOutputStream. I want to update this file but without having to re-write all the unmodified data back to the file and without losing the unmodified data. I only want to re-write the portion of the data that has been modified. Is there a way to do this without clearing out the file?

Thanx,
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want to append new data to the file? FileOutputStream has constructors which take a boolean argument that indicates if the new data replaces existing data or appends to it.
If you want to overwrite the existing data in place, you can do it with RandomAccessFile, but the new data must be the same length as the data you are replacing or you will overwrite or not replace the existing data.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!