You need to add an import statement for File
class.
import java.io.File; // import statement for File.
Also you can just use the fileName
to create the new File
instead of giving the hardcoded name again.
String FileName = "myths.txt";
Scanner input = new Scanner(new File(FileName));
Since you're creating a new Scanner object using the new File(fileName)
, this constructor of Scanner
throws a FileNotFoundException
which needs to be handled.
I advice you move this code to a method inside the class and handle the FileNotFoundException
either by having a throws
clause or a try-catch
around the code creating a new Scanner using a File object.
You can see an example here on how to handle a checked exception, in your case, FileNotFoundException
.