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 中的便捷方法真的很有帮助。
