将行写入文本文件并更改预览
我可以将一行文本写入文件并在每次调用 WriteLine
后查看更改吗?现在,只有在关闭 StreamWriter
后,我才能看到此文件中的更改。
StreamWriter sw = new StreamWriter(string path);
sw.WriteLine("text");
在这个地方,我想预览我的文件
sw.Close();
,现在我只在此时看到写入的行
Can I write line of text into file and see changes after each call WriteLine
? Now I see changes in this file only after closing StreamWriter
.
StreamWriter sw = new StreamWriter(string path);
sw.WriteLine("text");
in this place I want to preview my file
sw.Close();
now I see writed line only in this moment
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,对
StreamWriter
的输出进行缓冲。试试这个:
请参阅此处 http://msdn.microsoft。 com/en-us/library/system.io.streamwriter.autoflush.aspx
Output to the
StreamWriter
is buffered by default.Try this:
See here http://msdn.microsoft.com/en-us/library/system.io.streamwriter.autoflush.aspx