如果使用FileOutputStream方法,则每次通过此方法写入文件时,都会丢失旧数据。是否可以通过写入文件而不会丢失旧数据FileOutputStream?
2 回答

墨色风雨
TA贡献1853条经验 获得超6个赞
使用采用File和的构造函数boolean
FileOutputStream(File file, boolean append)
并将布尔值设置为true。这样,您写入的数据将被附加到文件的末尾,而不是覆盖已经存在的数据。

GCT1015
TA贡献1827条经验 获得超4个赞
使用构造函数将材料附加到文件:
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);
添加回答
举报
0/150
提交
取消