如何用FileOutputStream写入数据而不丢失旧数据?

发布于 2024-12-21 14:22:07 字数 105 浏览 4 评论 0原文

如果您使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆追雨的时光 2024-12-28 14:22:07

使用采用 Fileboolean 的构造函数

FileOutputStream(File file, boolean append) 

,并将布尔值设置为 true。这样,您写入的数据将被附加到文件的末尾,而不是覆盖已经存在的数据。

Use the constructor that takes a File and a boolean

FileOutputStream(File file, boolean append) 

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.

云雾 2024-12-28 14:22:07

使用构造函数将材料附加到文件:

FileOutputStream(File file, boolean append)
Creates a file output stream to write to the file represented by the specified File object.

因此,要附加到文件“abc.txt”,请使用

FileOutputStream fos=new FileOutputStream(new File("abc.txt"),true);

Use the constructor for appending material to the file:

FileOutputStream(File file, boolean append)
Creates a file output stream to write to the file represented by the specified File object.

So to append to a file say "abc.txt" use

FileOutputStream fos=new FileOutputStream(new File("abc.txt"),true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文