title: ObjectInputStream being initialised causes an EOFException of the type IOException
body: <p>I have been writing a to-do list app in java and each todo item is stored as an object of the class ToDo (which I created).<br>
  The ToDo class is serializable and I am using an ObjectOutputStream to write the objects to a text file. I close the ObjectOutputStream after doing this.<br>
  I should probably mention that currently my text file is empty as there are no todos in it and GUI.items is a static ArrayList in my GUI class.</p>
  
  <p>When I run the method that reads the files, an IO exception is thrown on the line:</p>
  
  <pre><code>ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
  </code></pre>
  
  <p>Here is the method that reads the files:</p>
  
  <pre><code>public void read() {
      try (FileInputStream fileInputStream = new FileInputStream("todo.txt")) {
  
          ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
  
          GUI.items.clear();
  
          while (objectInputStream.readObject() != null) {
              GUI.items.add((ToDo) objectInputStream.readObject());
          }
  
          GUI.updateInterface();
  
          objectInputStream.close();
  
      } catch (FileNotFoundException e) {
          e.printStackTrace();
          //JOptionPane.showMessageDialog(null, "Error: To-Do List not found.\nPlease contact the developer.", "Error", JOptionPane.ERROR_MESSAGE);
      } catch (IOException e) {
          JOptionPane.showMessageDialog(null, "Error: To-Do List could not be opened.\nPlease contact the developer.", "Error", JOptionPane.ERROR_MESSAGE);
      } catch (ClassNotFoundException e) {
          JOptionPane.showMessageDialog(null, "Error: To-Do List object type could not be found.\nPlease contact the developer.", "Error", JOptionPane.ERROR_MESSAGE);
      }
  }
  </code></pre>
  
  <p>Why is this exception being thrown and how can I fix it? Thanks.</p>