If you want to write at the end of the file, just seek there and write. If you want to write somewhere else in the file and you are going to write exactly the same length of data as you are replacing, seek there and write. If you are going to be inserting, rather than replacing, you'll need to either dump to a backup and re-write the whole file, or dump into memory, seek to the begining, truncate, the file, dump back from memory and save.