猿问

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

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



Smart猫小萌
浏览 874回答 2
2回答

墨色风雨

使用采用File和的构造函数booleanFileOutputStream(File file, boolean append) 并将布尔值设置为true。这样,您写入的数据将被附加到文件的末尾,而不是覆盖已经存在的数据。

GCT1015

使用构造函数将材料附加到文件: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);
随时随地看视频慕课网APP

相关分类

Java
我要回答