in reply to adding a line to the beginning of a file

Depends. What size is the file? Can the entire thing be safely loaded into memory at once, or do you want to edit it in small pieces? If the former, it's just a matter of loading the file into a string or array and then printing it back with an extra line put at the beginning. If the latter, you open a new file under a different name from the original, write your new line to it, then read chunks from the old file and print them to the new file until you run out of chunks. Unlink the old file, rename the new file.

We can give more specific code when we have some information about why you're trying to do this.

  • Comment on Re: adding a line to the beginning of a file