View Full Version : Java DataInputStream question

02-09-2005, 05:19 PM
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:

while (!in.eof) {

02-09-2005, 06:10 PM
DataInput::readInt (http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInput.html#readInt())

myInt = dis.readInt()

} catch (EOFException e)
System.err.println("Unexpected end of file!");

However, you are better off checking the length of the file before working with it.

File f = new File(filename);
long length = f.length();