Java DataInputStream question

This is a discussion on Java DataInputStream question within the A Brief History of Cprogramming.com forums, part of the Community Boards category; hey im reading a binary file of numbers into somthing, problem is I only knew how to read from text ...

  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 05: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, 03:12 PM
  5. A question for .. java!
    By McAuriel in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-01-2002, 10:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21