Question

I am reading from a .dat file with an unknown amount of objects within it. What I want to do is loop through the file by using the .readObject() method. Is there a way I can determine the amount of times to read the file similar to the way the .hasNext() method works for Scanner?

For example, I would normally use a while loop with hasNext() as a parameter.

while (scFile.hasNext()){ 
   x = scFile.nextInt();
}

Thanks in advance.

Was it helpful?

Solution

Just read the stream until EOFException is thrown. The method you are looking for does not exist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top