如何用FileOutputStream写入数据而不丢失旧数据?
如果您使用 FileOutputStream
方法,则每次通过此方法写入文件时,您都会丢失旧数据。是否可以通过 FileOutputStream 写入文件而不丢失旧数据?
If you work with FileOutputStream
methods, each time you write your file through this methods you've been lost your old data. Is it possible to write file without losing your old data via FileOutputStream
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用采用
File
和boolean
的构造函数,并将布尔值设置为
true
。这样,您写入的数据将被附加到文件的末尾,而不是覆盖已经存在的数据。Use the constructor that takes a
File
and aboolean
and set the boolean to
true
. That way, the data you write will be appended to the end of the file, rather than overwriting what was already there.使用构造函数将材料附加到文件:
因此,要附加到文件“abc.txt”,请使用
Use the constructor for appending material to the file:
So to append to a file say "abc.txt" use