title: Java read object input stream into arraylist?
body: <p>The method below is supposed to read a binary file into an <code>arrayList</code>. But getting a <code>java.io.EOFException</code>:</p>
  
  <pre>
  at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2553)
  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1296)
  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
  at .... Read(Tester.java:400) 
  at .... main(Tester.java:23)
  </pre>
  
  <p>Line 23 at main just calls the method, line 400 is the while loop below. Any ideas?</p>
  
  <pre><code>private static void Read() {
      try {
          ObjectInputStream objIn = new ObjectInputStream(new FileInputStream("/file.bin"));
          while (objIn.readObject() != null) {
              list.add((Libreria) objIn.readObject());
          }
          objIn.close();
      } catch(Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>