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

查看:26
本文介绍了如何在不丢失旧数据的情况下使用 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?

推荐答案

使用带有 Fileboolean

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天全站免登陆