title: Exception generated for is.readObject. why?
body: <p>I have a game that regularly saves the game current status to a file (by writing a serialized object to a file).The user can resume  the game later on and it will read that object  and build the game from there.</p>
  
  <p>This seems to be working fine, but sometimes I get this exception</p>
  
  <pre><code>java.io.EOFException
          at java.io.DataInputStream.readByte(DataInputStream.java:98)
          at java.io.ObjectInputStream.nextTC(ObjectInputStream.java:506)
          at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:778)
          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
          at com.myGame.GameState.loadFromFile
          at com.myGame.GameState.loadGame
  </code></pre>
  
  <p>And here is the loadFromFile code</p>
  
  <pre><code>         try {
      FileInputStream fis = mActivity.openFileInput(fileName);
      ObjectInputStream is = new ObjectInputStream(fis);
      stateDetails = (StateDetails)is.readObject();//exception is generated here
  
      is.close();
      fis.close();
  } catch (Exception e) {
      MyApplication.SWERR(e);
  }
  </code></pre>
  
  <p>I don't understand why would this happen. Its one time object saving and reading. No loops involved to reach end of file. Why would it be generated?
  Any help is appreciated ........thanks</p>
  
  <p>Edit: this is how I do the saving</p>
  
  <pre><code>FileOutputStream fos = mActivity.openFileOutput(fileName, Context.MODE_PRIVATE);
              ObjectOutputStream os = new ObjectOutputStream(fos);
              os.writeObject(stateDetails);
              os.flush();
              fos.flush();
              os.close();
              fos.close();
  </code></pre>