using C# VS 2010, windows forms. My goal is to open and close the file only once and "overwrite" it multiple times. I never want to append. The reason for opening and closing the file once is I want the write operation to be fastest.
I am passing append = false in streamwriter constructor but it still appends and not overwrite.
private void testSpeed()
{
StreamWriter sw1 = new StreamWriter(@"d:\logfolder\overwrite.txt", false);
sw1.AutoFlush = true;
for (int i = 0; i < 5000; i++)
{
sw1.Write(i);
}
sw1.Close();
}
My expected output is the file should only have 4999 but I am getting this instead 0123456789101112131415161718192021222324252627282930313233............... all the way to 4999
this file already exists d:\logfolder\overwrite.txt
Any ideas what I Am doing wrong?