A
AdemusPrime
I need to write data to a file in a loop. I get a "file already in
use" error on the second loop. The problem is, I don't know the name
of the file until I'm in the loop. How can I keep a file open for
writing in a loop?
while ((data = log.ReadLine()) != null)
{
string date = data.Substring(0, 10);
FileStream fileOut = new FileStream(dir + date + name,
FileMode.OpenOrCreate, FileAccess.Write);
fileOut.Write(Encoding.UTF8.GetBytes(data), 0, data.Length);
fileOut.Flush();
}
use" error on the second loop. The problem is, I don't know the name
of the file until I'm in the loop. How can I keep a file open for
writing in a loop?
while ((data = log.ReadLine()) != null)
{
string date = data.Substring(0, 10);
FileStream fileOut = new FileStream(dir + date + name,
FileMode.OpenOrCreate, FileAccess.Write);
fileOut.Write(Encoding.UTF8.GetBytes(data), 0, data.Length);
fileOut.Flush();
}