Java FileInputStream ObjectInputStream reaches end of file EOF

Posted by user69514 on Stack Overflow See other posts from Stack Overflow or by user69514
Published on 2010-04-12T23:50:31Z Indexed on 2010/04/12 23:52 UTC
Read the original article Hit count: 589

I am trying to read the number of line in a binary file using readObject, but I get IOException EOF. Am I doing this the right way?

    FileInputStream istream = new FileInputStream(fileName);
    ObjectInputStream ois = new ObjectInputStream(istream);

    /** calculate number of items **/
    int line_count = 0;
    while( (String)ois.readObject() != null){            
        line_count++;
    }

© Stack Overflow or respective owner

Related posts about file-read

Related posts about fileinputstream