problems with ObjectInputStream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blackraven1425
    New Member
    • Mar 2008
    • 27

    problems with ObjectInputStream

    The ObjectInputStre am in this code is giving a EOFException. Do I need to do anything special to get this to work withou the EOF exception? It gives the exception at the line of the first instance of ObjectInputStre am.

    public static ArrayListSerial getList() {
    try {
    try{
    try {
    ObjectInputStre am in = new ObjectInputStre am(new BufferedInputSt ream(new FileInputStream ("J:\\collectib les.dat")));
    Object inObject;
    inObject = in.readObject() ;
    if(inObject instanceof ArrayListSerial ){
    ArrayListSerial inObject2 = (ArrayListSeria l)inObject;
    return inObject2;
    }
    }catch(EOFExcep tion z){
    System.out.prin tln("Not");
    z.printStackTra ce();
    }
    } catch (ClassNotFoundE xception e) {
    e.printStackTra ce();
    }
    } catch (FileNotFoundEx ception e) {
    ArrayListSerial collectibles = new ArrayListSerial (100);
    item item = new item();
    item.changeName ("test");
    collectibles.ad d(item);
    saveList(collec tibles);
    e.printStackTra ce();
    return collectibles;

    }
    return null;
    }
  • blackraven1425
    New Member
    • Mar 2008
    • 27

    #2
    Oh,and this is after it makes the array for the first time too. The file exists, but there's no data in it.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by blackraven1425
      The ObjectInputStre am in this code is giving a EOFException. Do I need to do anything special to get this to work withou the EOF exception? It gives the exception at the line of the first instance of ObjectInputStre am.
      I bet you didn't flush/close the ObjectOutputStr eam properly when you wrote
      the object to a file.

      kind regards,

      Jos

      Comment

      • blackraven1425
        New Member
        • Mar 2008
        • 27

        #4
        That was absolutely it. Thanks a lot for the help!

        Comment

        Working...