Reading a text file

A Scanner on a File reads a text file a token or a line at a time, hasNext asking whether anything is left, so a while loop reads exactly as much as the file holds, and a missing file has to be declared with throws IOException.

From AP Computer Science A.