Question

My problem is that my project (a simple Inventory in which Items are Serialized to a folder and then deserialized) is throwing a "java.io.StreamCorruptedException: invalid stream header: 00000001" when I try to deserialize the information. I did not have a problem before; however, when I manually deleted one of the serialized files with Finder(mac), this is when the Exception was thrown. My code for deserializing is:

private void compileInventory() {
    //run through text file and create inventory 

    Inv = new <Item>ArrayList();
    File f = new File(loc);
    File[] list = f.listFiles();
    Inv.clear();
    if (f.exists()) {
        for (File n : list) {

                try {
                    FileInputStream fileIn = new FileInputStream(n.getAbsolutePath());
                    ObjectInputStream in = new ObjectInputStream(fileIn);
                    Inv.add((Item) in.readObject());
                    in.close();
                    fileIn.close();
                } catch (IOException i) {
                    i.printStackTrace();
                    return;
                } catch (ClassNotFoundException c) {
                    System.out.println("Item class not found");
                    c.printStackTrace();
                    return;
                }
            }

    }
}
Was it helpful?

Solution

Could it be that your mac has created some system files in that folder, and now your app is trying to deserealize them?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top