title: Java Mysterious EOF exception with readObject
body: <p>The following code produces an <code>EOFException</code>. Why is that?</p>
  
  <pre><code>public static Info readInfoDataFromFile(Context context) {
      Info InfoData = null;
      FileInputStream fis = null;
      ObjectInputStream ois = null;
      Object object = null;
  
      if (context.getFileStreamPath("InfoFile.dat").exists()) {
          try {
              fis = context.openFileInput("InfoFile.dat");
              ois = new ObjectInputStream(fis);
              Object temp;
              try {
                  // here it throws EOF exception in while loop 
                  while ((temp = ois.readObject()) != null) {
                      object = temp;
                  }
              } catch (NullPointerException npe) {
                  npe.printStackTrace();
              } catch (EOFException eof) {
                  eof.printStackTrace();
              } catch (FileNotFoundException fnfe) {
                  fnfe.printStackTrace();
              }
          } catch (Exception e) {
              e.printStackTrace();
          } finally {
              try {
                  if (ois != null) {
                      ois.close();
                  }
              } catch (IOException e) {
                  e.printStackTrace();
              }
              try {
                  if (fis != null) {
                      fis.close();
                  }
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  </code></pre>
  
  <p>StackTrace:</p>
  
  <pre><code>03-07 14:29:01.996: WARN/System.err(13984): java.io.EOFException
  03-07 14:29:01.996: WARN/System.err(13984):     at java.io.DataInputStream.readByte(DataInputStream.java:131)
  03-07 14:29:01.996: WARN/System.err(13984):     at java.io.ObjectInputStream.nextTC(ObjectInputStream.java:628)
  03-07 14:29:01.996: WARN/System.err(13984):     at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:907)
  03-07 14:29:01.996: WARN/System.err(13984):     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)03-07 14:29:01.996: WARN/System.err(13984):     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
  03-07 14:29:01.996: WARN/System.err(13984):     at 
  </code></pre>