title: Reading from file gives java.io.StreamCorruptedException: invalid stream header: 73720027
body: <p>I'm trying to save a LinkedList to a text file that has the ability to append but when I am reading   it I get an exception "java.io.StreamCorruptedException: invalid stream header: 73720027"</p>
  
  <p>I saw that there are many questions about the same problem but nothing had helped me to solve the issue. What am I doing wrong?</p>
  
  <pre><code>  public void saveResult() {
              File file = new File(context.getFilesDir(), "" + File.separator + "prevResultt.txt");
  
              FileOutputStream fileOutputStream;
              ObjectOutputStream objectOutputStream;
              try {
                  fileOutputStream = Objects.requireNonNull(context).openFileOutput("prevResultt.txt", MODE_PRIVATE);
                  if (!file.exists()) {
                      objectOutputStream = new ObjectOutputStream(fileOutputStream);
                  } else {
                      objectOutputStream = new AppednableOOS(fileOutputStream);
                  }
                  objectOutputStream.writeObject(resultsLinkedList);
                  objectOutputStream.close();
              } catch (IOException f) {
                  f.printStackTrace();
              }
  
          }
  
  
  
  public LinkedList&lt;Result&gt; loadResult() {
      results = new LinkedList&lt;&gt;();
      File file = new File(getContext().getFilesDir(), "" + File.separator + "prevResultt.txt");
      if (file.exists()) {
          try {
              ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(file));
              results = (LinkedList) objectInputStream.readObject();
              objectInputStream.close();
          } catch (Exception e) {
  
              e.printStackTrace();
          }
      }
      return results;
  }
  
  
  
  import java.io.IOException;
  import java.io.ObjectOutputStream;
  import java.io.OutputStream;
  
  public class AppednableOOS extends ObjectOutputStream {
  
      public AppednableOOS(OutputStream out) throws IOException {
          super(out);
      }
  
      @Override
      protected void writeStreamHeader() throws IOException {
        reset();
      }
  }  
  </code></pre>