title: Writing Data Structures to files using FileOutputStream?
body: <p>I have an android application and want to store/retrieve to memory a data structure that I created on the onPause()/onResume() methods so that the data will persist between runs via FileOutputStream/FileInputStream, which is the standard practice for this. </p>
  
  <p>So, how do I save a data structure to a file so that I can obtain it later (I've seen examples of doing it with Strings but not other objects)? Am I forced to create a getBytes() function for my data structure and the subsequent objects which it contains in addition to making constructors for all of these objects that creates them from byte arrays?</p>
  
  <p>Edit: Ah, okay; so this is called serialization.
  Is the the following correct?</p>
  
  <p>To write:</p>
  
  <pre><code>FileOutputStream fileOut = new FileOutputStream("filename");
  ObjectOutputStream out = new ObjectOutputStream(fileOut);
  out.writeObject(e);
  out.close();
  fileOut.close();
  </code></pre>
  
  <p>To read:</p>
  
  <pre><code>FileInputStream fileIn = new FileInputStream("filename");
  ObjectInputStream in = new ObjectInputStream(fileIn);
  e = (ObjectType) in.readObject();
  in.close();
  fileIn.close();
  </code></pre>
  
  <p>Edit2: Also, the data structure and contained objects (and sub-objects) should all implement Serializable.
  So for instance, if I had a BST of ArrayLists of Dogs then I would make the BST, ArrayList, and Dog classes all implement Serializable and then call the functions above.</p>
  
  <p>Is all of this correct?</p>