如何使用FileOutputStream写入数据而不丢失旧数据? [英] How to write data with FileOutputStream without losing old data?

查看:105
本文介绍了如何使用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?

推荐答案

使用带文件的构造函数和布尔值

FileOutputStream(File file, boolean append) 

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

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.

这篇关于如何使用FileOutputStream写入数据而不丢失旧数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆