File writes in a loop
- From: AdemusPrime@xxxxxxxxx
- Date: Fri, 16 May 2008 12:35:27 -0700 (PDT)
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();
}
.
- Follow-Ups:
- Re: File writes in a loop
- From: AdemusPrime
- Re: File writes in a loop
- From: AdemusPrime
- Re: File writes in a loop
- From: Paul E Collins
- Re: File writes in a loop
- From: zacks
- Re: File writes in a loop
- From: parez
- Re: File writes in a loop
- From: Hilton
- Re: File writes in a loop
- Prev by Date: Re: .NET apps not being recognized as being in the Intranet Zone
- Next by Date: Re: Not getting all window messages from IMessageFilter?
- Previous by thread: [rdlc reporting] problems with unicode chars in pdf
- Next by thread: Re: File writes in a loop
- Index(es):
Relevant Pages
|
Loading