It is not possible to "replace" a line in file (unless the replacement has exactly the same number of bytes as the part being replaced) and neither it is possible to "insert" a line in the middle of a file. If you need something like this, you have to rewrite every successive byte of the file. So it's usually easier to just read the file to memory, modify it there and then write everything back.
Bookmarks