how to check if the file has remaining without reading from it java

Java
Scanner scanner = new Scanner(new File("filename"));
while (scanner.hasNextLine()) {
   String line = scanner.nextLine();
   // process the line
}

Source

Also in Java: