在.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.
更多推荐
发布评论