Thursday, August 1, 2013

Close a file effectly

My case is a little complex.

while (!hasHitEnd)
{
foreach (var y in query)
{
TextWriter tw = new StreamWriter(outputFileName, true);
tw.WriteLine(y.Path + "_" + y.Name);
tw.Close();
}
}

There is a while loop outside of foreach query, your File.WriteAllLines will create a new file. I just want to append line to the existing file.

No comments:

Post a Comment