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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top