Updating a file without overwriting the previous data
posted 11 years ago
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?
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.