簡體   English   中英

讀取序列化對象作為流

[英]Read a serialized object as a stream

我已經以這種方式序列化了一個巨大的鏈表(150mb):

public void serialize(ArrayList<LinkedList> e, String file){    
try {
        FileOutputStream fileOut =
                new FileOutputStream("file+".ser");
        ObjectOutputStream out = new ObjectOutputStream(fileOut);
        out.writeObject(e);
        out.close();
        fileOut.close();

    }catch(IOException i)
    {
        i.printStackTrace();
    }
}

現在,我想以一種非阻塞的方式將其作為流讀取,這與以下方法相反:

public ArrayList deserialize(File file){
    ArrayList<LinkedList> e = null;
    try
    {
        FileInputStream fileIn = new FileInputStream(file);
        ObjectInputStream in = new ObjectInputStream(fileIn);
        e = (ArrayList<LinkedList>) in.readObject();
        in.close();
        fileIn.close();
        return e;
    }catch(IOException i)
    {
        i.printStackTrace();
        return null;
    }catch(ClassNotFoundException c)
    {
        System.out.println("Object not found");
        c.printStackTrace();
        return null;
    }
}

在反序列化過程仍在運行但尚未完成時,是否可以使用部分反序列化的數據?

你不能 不存在與文件無阻塞的I / O之類的問題。 您的問題沒有道理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM