1. Open a new file
2. Copy the content of the old file into the new file up to the place where you want to insert your text
3. Write your text to the new file
4. Copy the rest of the old file to the new file
5. Close the new file
6. Remove the old file
7. Rename the new file with the name of the old file
Another algorithm is possible if the file is smaller than your available memory:
1. Read the entire file into memory
2. Write data from memory up to the place where you want to insert your text
3. Write your text
4. Write the end of your data from memory
Bookmarks