繁体   English   中英

在控制台应用程序中覆盖txt文件C#中的输出

[英]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();  
}

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

true部分意味着“追加” - 要么完全摆脱它,在这种情况下你将使用StreamWriter构造函数重载,它会被defalut覆盖,或者将true改为false

或者最好只使用:

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

当您可以一次性指定所有数据时, File中的便捷方法确实很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM