I have programmed a C# console application with a StreamWriter: Now I want to close the StreamWriter to write all elements in filename.txt but I want to use the same StreamWriter again, how can I do it? Open after Close?
Example:
StreamWriter Stream = new StreamWriter(filename,true);
for(;;)
{
//this is a endless loop
Stream.WriteLine("THIS MUST BE WRITE TO MY DEVICE NOW")
//now i must use
Stream.Close();
//or
Stream.Dispose();
//or
Stream.Close();
}
// When it begin again from the top of the loop the StreamWriter doesn´t work.
Now I want to close the StreamWriter to write all elements in filename.txt but I want to use the same StreamWriter again, how can I do it? Open after Close?
Stream.Flush();
// it works fine