Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me with the below code, it throws an error as "file not found".

import java.io.File;

import java.util.*;

public class Hangman1 {

    public static void main(String[] args) throws Exception {

        Scanner input = new Scanner(new File("word.txt"));          

        String in = "";         

        in = input.nextLine();          

    }

}

Any help would be appreciated.

1 Answer

0 votes
by (26.7k points)

Basically, in able to rectify this error you need to put that file "word.txt" as the child of the project and should be peer to src, something like this:

Project_Root

    src

    word.txt

I hope this will help.

Want to know more about Java? Prefer this tutorial on Learn Java.

Want to become a Java Expert? Join Java Training now!!

Browse Categories

...