Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 附加对象现有文件_Java - Fatal编程技术网

Java 附加对象现有文件

Java 附加对象现有文件,java,Java,我想在现有文件中附加可序列化对象,但显然它会删除以前存储的对象 对于参数文件F,我发送新文件(文件路径)。也许我的错误就在那里 谢谢你的帮助 public static void wrinting(File[] tab, File f) throws Exception{ ArrayList<ImageClass> obj = imagesArray(tab); ObjectOutputStream oos; try { oos = new

我想在现有文件中附加可序列化对象,但显然它会删除以前存储的对象

对于参数文件F,我发送新文件(文件路径)。也许我的错误就在那里

谢谢你的帮助

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)