使用StreamWriter的附加文本 [英] Append text using StreamWriter
问题描述
这可能是一个非常简单的问题。在C#中我试图写一个简单的方法,叫我DebugWrite的方法,写出自己的程序中捕获到本地存储的文本文件中的任何异常。我当前的代码每次只写入一个新的文件,使用的StreamWriter
如何编程它来检查,如果该文件已经存在,如果是追加到当前文本?。 IE浏览器:
如果(〜存在(DEBUG.TXT)
{
编写新DEBUG.TXT。
}
,否则如果(存在(DEBUG.TXT))
{
追加新的文本。
}
使用(StreamWriter的作家=新的StreamWriter(DEBUG.TXT,真))
{
writer.WriteLine(不管你文字);
}
第二个真正的参数告诉它追加。
的 http://msdn.microsoft.com/en-us/library/36b035cb.aspx
This is probably a pretty simple question. In C# I'm trying to write a simple method, called my "DebugWrite" method, to write out any exceptions caught within my program to a text file stored locally. My current code only writes a new file every time, using StreamWriter
How do you program it to check if the file already exists, and if so to append to the current text?. IE:
If(~Exist(debug.txt)
{
Write new debug.txt.
}
else if(exist(debug.txt))
{
Append new text.
}
using(StreamWriter writer = new StreamWriter("debug.txt", true))
{
writer.WriteLine("whatever you text is");
}
The second "true" parameter tells it to append.
http://msdn.microsoft.com/en-us/library/36b035cb.aspx
这篇关于使用StreamWriter的附加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!