1
if (string.IsNullOrEmpty(indata))
{
    StreamWriter sw = new StreamWriter(@"c:\arjun.txt", true);
    sw.WriteLine("0");
    sw.Close();  
}

这是我的代码。如何覆盖arjun.txt我需要单个结果的文件中的结果。

4

1 回答 1

4

true部分的意思是“附加” - 要么完全摆脱它,在这种情况下,您将使用StreamWriter由默认值覆盖的构造函数重载,或者更改truefalse.

或者最好只使用:

File.WriteAllLines(@"c:\argun.txt", new[] {"0"});

当您可以一次性指定所有数据时,其中的便捷方法File非常有用。

于 2012-12-07T11:10:13.270 回答