我使用scanner类来读取位于我的源文件夹目录中的“maze.txt”,但是我收到了错误。这是错误我一直在
Exception in thread "main" java.io.FileNotFoundException: maze.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.util.Scanner.<init>(Scanner.java:656)
at mazetr.ch18ex20.main(ch18ex20.java:144).......:
public static void main( String[] args ) throws IOException
{
Scanner in = new Scanner( new File( "maze.txt" ) );
}
答案 0 :(得分:0)
如果你在mazetr包上有maze.txt,你必须介绍:
Scanner in = new Scanner( new File( "src\\mazetr\\maze.txt" ) );
如果你在另一个包装上有maze.txt:
Scanner in = new Scanner( new File( "src\\anotherpackage\\maze.txt" ) );