You read the object during the test:
while (objIn.readObject() != null)
Then you read the following object in:
libraryFromDisk.add((MediaLibrary) objIn.readObject());
So, in one iteration, you should only read one object
private static void Load() { try { ObjectInputStream objIn = new ObjectInputStream(new FileInputStream("/file.bin")); Object object = objIn.readObject(); while (object != null) { libraryFromDisk.add((MediaLibrary) object); object = objIn.readObject(); } objIn.close(); } catch(Exception e) { e.printStackTrace(); } }
source share