[英]Overwrite output in txt file C# in console application
if (string.IsNullOrEmpty(indata))
{
StreamWriter sw = new StreamWriter(@"c:\arjun.txt", true);
sw.WriteLine("0");
sw.Close();
}
This is my code. 这是我的代码。 How can I overwrite a result in arjun.txt
file I need single result. 如何覆盖arjun.txt
文件中的结果我需要单个结果。
The true
part means "append" - either just get rid of it entirely, in which case you'll use the StreamWriter
constructor overload which overwrites by defalut, or change true
to false
. true
部分意味着“追加” - 要么完全摆脱它,在这种情况下你将使用StreamWriter
构造函数重载,它会被defalut覆盖,或者将true
改为false
。
Or preferably, just use: 或者最好只使用:
File.WriteAllLines(@"c:\argun.txt", new[] {"0"});
When you can specify all the data in one go, the convenience methods in File
are really helpful. 当您可以一次性指定所有数据时, File
中的便捷方法确实很有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.