Frage

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.

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top