如果您使用FileOutputStream
方法,那么每次通过这些方法编写文件时,您都会丢失旧数据。能否通过FileOutputStream
在不丢失旧数据的情况下写入文件
发布于 2011-12-17 20:36:41
使用接受File
和boolean
参数的构造函数
FileOutputStream(File file, boolean append)
并将布尔值设置为true
。这样,您写入的数据将被附加到文件的末尾,而不是覆盖文件中已有的内容。
发布于 2011-12-17 20:37:14
使用构造函数将材质附加到文件:
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);
https://stackoverflow.com/questions/8544771
复制相似问题