You have to completely rewrite the file.
open original file for reading
open temp file for writing
while not end-of-input-file
read a line from input file
if this is the line to be replaced
write new line to output file
otherwise
write the line to the output file
end loop
close both files
delete original file
rename temp file with the name of the original file
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Yes, you could just read the entire input file into memory then rewrite it back to the original file. But ... what will you do with a huge file whose size is several gigs? Using a temp file like I described is the general method to do what you want because it works with files of any size without consuming too much memory.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343