When reading a file with the Scanner class I tend to use



Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {

}