Skip to content
Advertisement

while EOF in JAVA?

Following to some forums answers I’m using this:

    while (fileReader.nextLine() != null) {
        String line = fileReader.nextLine();
        System.out.println(line);
    }  

… but it throws exception at the end anyway (Exception in thread “main” java.util.NoSuchElementException: No line found)

Advertisement

Answer

you should use while (fileReader.hasNextLine())

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement