Adding a Line to the Middle of a File with .NET

后端 未结 6 1190
你的背包
你的背包 2020-12-03 21:45

Hello I am working on something, and I need to be able to be able to add text into a .txt file. Although I have this completed I have a small problem. I need to write the st

6条回答
  •  暖寄归人
    2020-12-03 22:23

    one of the trick is file transaction. first you read the file up to the line you want to add text but while reading keep saving the read lines in a separate file for example tmp.txt and then add your desired text to the tmp.txt (at the end of the file) after that continue the reading from the source file till the end. then replace the tmp.txt with the source file. at the end you got file with added text in the middle :)

提交回复
热议问题