How to write data to a text file without overwriting the current data

前端 未结 8 804
南笙
南笙 2020-12-15 18:00

I can\'t seem to figure out how to write data to a file without overwriting it. I know I can use File.appendtext but I am not sure how to plug that into my syntax. Here is m

相关标签:
8条回答
  • 2020-12-15 18:29

    Look into the File class.

    You can create a streamwriter with

    StreamWriter sw = File.Create(....) 
    

    You can open an existing file with

    File.Open(...)
    

    You can append text easily with

    File.AppendAllText(...);
    
    0 讨论(0)
  • 2020-12-15 18:36

    You have to open as new StreamWriter(filename, true) so that it appends to the file instead of overwriting.

    0 讨论(0)
提交回复
热议问题