title: Serializable simple Object IOException
body: <p><strong>Found the solution:</strong>
  you have to open the Streams like this:</p>
  
  <pre><code>FileInputStream  inputStream = openFileInput(FILENAME);
  ObjectInputStream ois = new ObjectInputStream(inputStream);
  </code></pre>
  
  <p>Same with Output. This fixed it for me, should anyone stumble upon this in search for an answer.</p>
  
  <p><strong>Original question:</strong>
  Through a few tests with <code>Toast</code>s I have found that when I call the Constructor for <code>ObjectOutputStream</code> I get an <code>IOException</code> thrown.</p>
  
  <p>My code looks like this. Note that this is merely a test project, and I can't even get this one to work.</p>
  
  <pre><code>    Button b = new Button(this);
      b.setText("write");
      b.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              try {
                  File f = new File("Filepath");
                  if (!f.exists()) {
                      f.createNewFile();
                  }
  
                  ObjectOutputStream oos = new ObjectOutputStream(
                          new FileOutputStream(f)); //IOException here!
  
                  Series x = new Series("Test", 20, 12);
                  // oos.writeObject(x);
  
                  oos.close();
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      });
  
      tv = new TextView(this);
      tv.setText("Not read anything yet!");
  
      Button r = new Button(this);
      r.setText("Read");
      r.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              try {
                  ObjectInputStream ois = new ObjectInputStream(
                          new FileInputStream(new File("Filepath")));
                  Series y = (Series) ois.readObject();
                  tv.setText(y.getName() + "-" + y.getNumOfSeason() + "-"
                          + y.getNumOfEpisode());
                  ois.close();
              } catch (StreamCorruptedException e) {
                  e.printStackTrace();
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      });
  </code></pre>
  
  <p>The problem seems to be my constructor call. Before I added the part with </p>
  
  <pre><code>if (!f.exists()) {
                  f.createNewFile();
              }
  </code></pre>
  
  <p>I got a <code>FileNotFoundException</code>.</p>
  
  <p>What am I doing wrong?</p>