Java 附加对象现有文件
我想在现有文件中附加可序列化对象,但显然它会删除以前存储的对象 对于参数文件F,我发送新文件(文件路径)。也许我的错误就在那里 谢谢你的帮助Java 附加对象现有文件,java,Java,我想在现有文件中附加可序列化对象,但显然它会删除以前存储的对象 对于参数文件F,我发送新文件(文件路径)。也许我的错误就在那里 谢谢你的帮助 public static void wrinting(File[] tab, File f) throws Exception{ ArrayList<ImageClass> obj = imagesArray(tab); ObjectOutputStream oos; try { oos = new
public static void wrinting(File[] tab, File f) throws Exception{
ArrayList<ImageClass> obj = imagesArray(tab);
ObjectOutputStream oos;
try {
oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
for (ImageClass i : obj) {
oos.writeObject(i);
}
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
publicstaticvoidwrint(文件[]选项卡,文件f)引发异常{
ArrayList obj=图像阵列(选项卡);
对象输出流oos;
试一试{
oos=新的ObjectOutputStream(新的BufferedOutputStream(新的FileOutputStream(f));
用于(i类图像:obj){
oos.writeObject(i);
}
oos.close();
}捕获(IOE异常){
e、 printStackTrace();
}
}打开
文件输出流,如下所示:
newfileoutputstream(f,true)