What could be causing Java to throw a FileNotFoundException even when the file exists?

If you’re still getting java FileNotFoundException, try catching the exception to get more details:

try (Scanner scan = new Scanner(new File("lines.txt"))) {
    while (scan.hasNextLine()) {
        System.out.println(scan.nextLine());
    }
} catch (FileNotFoundException e) {
    System.out.println("File not found! Check the file path and permissions.");
    e.printStackTrace();
}

This way, you’ll get a more detailed error message, which might give you a clue as to why Java can’t find the file.