我似乎无法弄清楚如何在不覆盖文件的情况下将数据写入文件。我知道我可以使用 File.appendtext 但我不确定如何将其插入我的语法中。这是我的代码:
TextWriter tsw = new StreamWriter(@"C:\Hello.txt");
//Writing text to the file.
tsw.WriteLine("Hello");
//Close the file.
tsw.Close();
我希望它每次运行程序时都写 Hello,而不是覆盖以前的文本文件。感谢您阅读本文。