I have a file where I need to append a checksum to the beginning. How would this be done? I don't think it's possible to insert data, so I can allocate space by writing 512 0s, but how would I overwrite them later?
Printable View
I have a file where I need to append a checksum to the beginning. How would this be done? I don't think it's possible to insert data, so I can allocate space by writing 512 0s, but how would I overwrite them later?
You can use java.io.RandomAccessFile or if the file is short it may be easier to rename the existing file, create a new file with the old filename and then write the data to append followed by the data in the renamed file. Finally you can delete the renamed file or if it's renamed to *.bak keep it as a previous version of the file.
Okay. Thank you!