in reply to begining of a file
Try something like this:
open a temportary file write something into it open the old file read the contents write it to the temporary file close both files rename the temporary