ObjectInputStream EOF test

I have the following code to read from .ser file.

File file =new File("/home/dhans/travelcache/test.ser");

ObjectInputStream is =new ObjectInputStream(

new BufferedInputStream(new FileInputStream(file)));

and i am reading from the input stream by

is.readObject();

my question is how to find out whether end of file is reached using

ObjectInputStream.i tried with something like the following

while(is.readObject() !=null){

// do something

}

but no use it is throwing java.io.EOFException if EOF is reached.

Is there a method/way to test whether end of file is reached.

any help would be helpful

tia,

dhanasekaran

[1020 byte] By [dhana007a] at [2007-10-3 2:32:56]
# 1
> but no use it is throwing java.io.EOFException if EOF> is reached.IIRC that's exactly the way it tells you that EOF is reached. What else could it do? Where's the difference between a serialized null and an EOF null?
CeciNEstPasUnProgrammeura at 2007-7-14 19:31:56 > top of Java-index,Java Essentials,New To Java...
# 2
and where does it say that ObjectInputStream.readObject() returns null at EOF?
ejpa at 2007-7-14 19:31:56 > top of Java-index,Java Essentials,New To Java...
# 3

Here's a template

try {

while (true) {

price = in.readDouble();

unit = in.readInt();

desc = in.readUTF();

System.out.format("You ordered %d units of %s at $%.2f%n",

unit, desc, price);

total += unit * price;

}

} catch (EOFException e) {

}

Just replace what needs to be replaced, don't ask me, i'm new to Java :(

Tjorriemorriea at 2007-7-14 19:31:56 > top of Java-index,Java Essentials,New To Java...