C # how to update a file (keep old data)
6 answers
One way is to specify true
for a flag Append
(in one of the constructor overloads StreamWriter
):
TextWriter tw = new StreamWriter(@"D:/duom.txt", true);
Note. Don't forget to wrap the operator using
.
+3
a source to share
You need to use an overload constructor with an add flag, and don't forget to make sure your stream is closed, complete:
using (TextWriter tw = new StreamWriter(@"D:\duom.txt", true))
{
tw.WriteLine("Text1");
}
+1
a source to share