Read and write into a same file

  • Thread starter Thread starter bnob
  • Start date Start date
B

bnob

I must read a txt file and when I found a line beginning with the word
"Backup", I must replace this line with "Save"

The read and the write must done into the same file!

I know how to read line after line a file (I use StreamReader), but how
can I write during I read the file ??
 
You could create a second text file and use a StreamWriter to write each
line from the original file to the new file as you process them. Then when
you are done reading delete the original and rename your new file.

Peter
 
Back
Top