title: Homework! ObjectInputStream(new FileInputStream("filename") never stops reading
body: <p>For the record, this is my Java programming assignment. It's a simple output some data to a file and read it back in type assignment. I've already done in previous classes simple writing to text files so I wanted to make this one more difficult. In my book there is a topic about using <code>ObjectOutputStream(new FileInputStream);</code> and <code>ObjectInputStream(new FileInputStream)</code> to read and write complete objects. Now, I'm sure that I'm writing 2 objects to this file, the first few tests I only wrote one and then saw the byte size double when I wrote 2. Both objects are of the same type. When I try to read them back in the program gets stuck on the first object in the file and never moves to the next and never throws <code>EOFException</code> to show the end of the file. Now I'm stumped. I've checked and rechecked the example in my book and searched online and I can't figure why I can't read back in these objects. I've still got plenty of time to complete this assignment so I'm not worried about getting it in on time.</p>
  
  <pre><code> import java.io.EOFException;
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
  
  
   public class TextFileIO {
       static int[] evenNumbers = new int[50];
       static int[] oddNumbers = new int[50];
  public static void main(String[] args) {
  
      int evenCount = 0;
      int oddCount = 0;
      for(int i = 0; i &lt; 100; i++){
          if(i % 2 == 0){
              evenNumbers[evenCount] = i;
              evenCount++;
          }
          else{
              oddNumbers[oddCount] = i;
              oddCount++;
          }
      }
      ArraySerializable even = new ArraySerializable(evenNumbers);
      ArraySerializable odd = new ArraySerializable(oddNumbers);
  
      writeToFile(even, odd);
  
  
      readFile();
  }
  
  public static void writeToFile(ArraySerializable array, ArraySerializable array2){
      try {
            ObjectOutputStream    output = new ObjectOutputStream(new FileOutputStream("numbers.dat"));
            output.writeObject(array);
            output.writeObject(array2);
            output.close();
      } catch (IOException e) {
  
          e.printStackTrace();
      }
  }
  
  public static void readFile(){
  
          ObjectInputStream input = null;
          try{
              while(true){
                  input = new ObjectInputStream(new FileInputStream("numbers.dat"));
                  ArraySerializable array;
                  array = (ArraySerializable) input.readObject();
                  int[] numbers = array.getNumbers();
                  for (int i = 0; i &lt; numbers.length; i++){
                      System.out.print(numbers[i] + " ,");
                  }
          }
          }catch(FileNotFoundException |  ClassNotFoundException |EOFException ex){
              ex.printStackTrace();
              return;
          }catch(IOException ex){
              ex.printStackTrace();
          }
          try {
              input.close();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and my ArraySerializable class:</p>
  
  <pre><code> import java.io.Serializable;
  
  
   public class ArraySerializable implements Serializable {
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  private int[] numbers;
  
  public ArraySerializable(int[] numbers){
      this.numbers = numbers;
  }
  
  public int[] getNumbers(){
      return numbers;
  }
  </code></pre>
  
  <p>}</p>