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.OpenOr Create, FileAccess.Writ e);
fileOut.Write(E ncoding.UTF8.Ge tBytes(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.OpenOr Create, FileAccess.Writ e);
fileOut.Write(E ncoding.UTF8.Ge tBytes(data), 0, data.Length);
fileOut.Flush() ;
}
Comment