in reply to Re^2: Elegant Way of Inserting Text at the Start of the File
in thread Elegant Way of Inserting Text at the Start of the File
In order to add content at the beginning of any disk file while preserving all the original content, there really is no practical way other than to create a new file, put the newly added content at the beginning of that new file, then copy/append the contents of the existing file, then rename the new one to replace (delete) the old one.
If you want to replace the initial portion of a file (or even any non-initial portion) while preserving the portion(s) that you don't replace, that can be done, but you have to be certain that the new data being put in has the exact same byte-count as the data being replaced.
In other words, anything that involves moving the "preserved" content to a different byte offset (relative to the beginning of the file) is best done by writing a new version of the file to replace the old one.
|
|---|