Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在写入之前从文本文件中删除所有内容?
System.IO.File.AppendAllText(@"D:\text.txt", Environment.NewLine + item);
这就是我给它写信的方式。
使用WriteAllText而不是AppendAllText
AppendAllText
System.IO.File.WriteAllText(@"D:\text.txt", item);