@fxm: Perfect.
@dodicat: I am not quite sure if I understand your intentions correctly (and you are not using
savefile in your example). Does it more or less mean, as in the para below, "load the whole file into a buffer, change what you need, write the buffer back"?
I must admit that I find the debate a bit academic. In my practical work,
- with text files I use Open with output mode (so it truncates) or in append mode (and it doesn't, obviously)
- with data files I use Open in binary or random mode to change existing data, which doesn't and shouldn't truncate.
jj2007 wrote:Juergen Kuehlwein wrote:I already have a file with let´s say 100 bytes of data. Now i change it´s content by writing 50 bytes of new data starting right at the beginning of the file opened in binary mode. This would leave 50 bytes of old data in my file. How can i cut off after 50 bytes, so that subsequent reads would only retrieve the new 50 bytes ?
There are situations where you don't start at the beginning of the file, but rather somewhere in the middle. If you write 50 bytes from position 20, and want to see 70 bytes and not more after closing the file, the solution (in the absence of SetEof) would be to read the first 20 bytes into a buffer, then open the file for output, print the 20 bytes, print the 50 bytes, close the file. Clumsy but it works.