在.Net中附加一个txt文件(Append a txt file in .Net)

编程入门 行业动态 更新时间:2024-10-15 00:18:47
在.Net中附加一个txt文件(Append a txt file in .Net)

我是在下面的代码的帮助下在.Net中创建一个txt文件。

StreamWriter writerVer = new StreamWriter(@"c:\Version.txt"); writerVer.WriteLine("Version : " + Context.Parameters["ver"]); File.SetAttributes(@"C:\Version.txt", FileAttributes.Hidden);

然后我需要通过保持上面的代码来更新下一行的文件。

此代码会覆盖整个文件。

StreamWriter writer = new StreamWriter(@"c:\Version.txt"); writer.WriteLine("Connection string : "+con);

Regrads,

Sachin K.

I am Creating a txt file in.Net with the help of below code.

StreamWriter writerVer = new StreamWriter(@"c:\Version.txt"); writerVer.WriteLine("Version : " + Context.Parameters["ver"]); File.SetAttributes(@"C:\Version.txt", FileAttributes.Hidden);

Then I need to Update the file on the next line by keeping the above code as it is.

This code overrites the entire file.

StreamWriter writer = new StreamWriter(@"c:\Version.txt"); writer.WriteLine("Connection string : "+con);

Regrads,

Sachin K

最满意答案

尝试这个

StreamWriter writerVer = new StreamWriter(@"c:\Version.txt", true);

StreamWriter构造函数有一个重载,它接受一个额外的bool参数来指示是否要追加。

try this

StreamWriter writerVer = new StreamWriter(@"c:\Version.txt", true);

There is an overload of the StreamWriter constructor that takes an additional bool parameter to indicate if you want to append or not.

更多推荐

本文发布于:2023-08-05 20:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437902.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   txt   Net   Append   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!