I'm trying to write to a file called output.txt
. It's fine the first time my code runs but the second time it throws an exception:
The process cannot access output1.txt because it is being used by another process
But I'm using this in a using
statement, and it should be disposed of and the file should be unlocked.
The constructor says if the file exists, it can either be appended to or overwritten
. Doesn't seem to be doing this because of the IOException it is throwing.
Why is this happening?
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@directoryURL + "\\output"+outputNumber+".txt", true))
{
foreach (string line in splitOutput)
{
file.WriteLine(line);
}
}