如果使用 FileOutputStream方法,每次通过这种方法写文件时,都会丢失旧数据。有没有可能写文件而不丢失你的旧数据通过 FileOutputStream?
FileOutputStream
Use the constructor that takes a File and a boolean
File
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.
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);