保存文件 C# - 不覆盖?
我每 60 秒将数据保存到一个文件,我让它每 60 秒保存一次,但它会删除以前添加的数据。有没有一种方法可以将其添加到文件而不是覆盖它。并且无需使用保存对话框,因为它是在后台完成的。
非常感谢任何反馈
I am saving data to a file every 60 secs, I have it saving every 60 secs ok but it deletes the previous data added. Is there a way in which it would add to the file rather than overwrite it. And without using save dialog as it is done in the background.
Any feedback is greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
看来以追加模式打开文件可以解决您的问题。
http://msdn.microsoft.com/en-us/library/3zc0w663.aspx
It seems opening the File in Append mode will solve your problem.
http://msdn.microsoft.com/en-us/library/3zc0w663.aspx
尝试,
Try,
在
FileStream
构造函数中指定FileMode.Append
。Specify
FileMode.Append
in theFileStream
constructor.使用
File
类AppendText
方法。Use
File
classAppendText
method.您可以在构造函数中将
StreamWriter
与append
一起使用为true
。请参阅此处。
You can use
StreamWriter
withappend
astrue
in the constructor.See here.
好的,我收到你的问题你有一个文件并且你想在其中保存新数据而不是替换它
你可以使用流阅读器打开其内容。并将要插入到文件中的数据附加到文件中
使用 writer 不会每次都保存文件,只需在该文件上附加数据,这样当您只是在该文件上附加某些内容时,它就不会覆盖该文件。
OK as i am getting your question You are having a File And you want to save new data on that instead of replacing it
You can just open its content using stream reader.and append that data you want to insert on the file
using writer don't save file each time just append data on that file so when you just appending something on that it will not overwrite that file.