Thread: Java DataInputStream question

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    104

    Java DataInputStream question

    hey im reading a binary file of numbers into somthing, problem is I only knew how to read from text files and there is (well I don't think), there is a .eof() in the DataInputStream.
    how I i keep reading numbers until i read the end of the input file? I know I can't put:

    Code:
    while (!in.eof) {
    ...
    }

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    DataInput::readInt
    Code:
    try
    {
        myInt = dis.readInt()
    
    } catch (EOFException e)
    {
        System.err.println("Unexpected end of file!");
        System.err.println(e.toString());
    }
    However, you are better off checking the length of the file before working with it.
    Code:
    File f = new File(filename);
    long length = f.length();
    Last edited by anonytmouse; 02-09-2005 at 06:16 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mats, the java answers
    By Jaqui in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 04-22-2008, 02:12 AM
  2. Java vs C to make an OS
    By WOP in forum Tech Board
    Replies: 59
    Last Post: 05-27-2007, 03:56 AM
  3. Windows GDI vs. Java Graphics
    By Perspective in forum Windows Programming
    Replies: 7
    Last Post: 05-07-2007, 10:05 AM
  4. How to use Java with C++
    By Arrow Mk 84 in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2003, 04:12 PM
  5. A question for .. java!
    By McAuriel in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-01-2002, 11:16 AM