You can't "insert" data into a text file. You can either overwrite or append. To acheive what you want you must read the file and write a new file: Read a line, write it to the new file (but without writing the newline character), then write the new data you want and a newline. Repeat.