if (string.IsNullOrEmpty(indata))
{
StreamWriter sw = new StreamWriter(@"c:\arjun.txt", true);
sw.WriteLine("0");
sw.Close();
}
这是我的代码。如何覆盖arjun.txt
我需要单个结果的文件中的结果。
该true
部分的意思是“附加” - 要么完全摆脱它,在这种情况下,您将使用StreamWriter
由默认值覆盖的构造函数重载,或者更改true
为false
.
或者最好只使用:
File.WriteAllLines(@"c:\argun.txt", new[] {"0"});
当您可以一次性指定所有数据时,其中的便捷方法File
非常有用。