C# Streamwriter Flus or Dispose or Close 后,再用?
C# Streamwriter after Flus or Dispose or Close, use again?
我用 StreamWriter 编写了一个 C# 控制台应用程序:
现在我想关闭 StreamWriter 以写入 filename.txt 中的所有元素,但我想再次使用同一个 StreamWriter,我该怎么做?
关闭后打开?
示例:
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.
现在我想关闭 StreamWriter 来写入 filename.txt 中的所有元素,但我想再次使用同一个 StreamWriter,我该怎么办?
关闭后打开?
Stream.Flush();
// it works fine
我用 StreamWriter 编写了一个 C# 控制台应用程序: 现在我想关闭 StreamWriter 以写入 filename.txt 中的所有元素,但我想再次使用同一个 StreamWriter,我该怎么做? 关闭后打开?
示例:
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.
现在我想关闭 StreamWriter 来写入 filename.txt 中的所有元素,但我想再次使用同一个 StreamWriter,我该怎么办? 关闭后打开?
Stream.Flush();
// it works fine