在写Scanner读取文件输入时出现:Exception in thread “main” java.io.FileNotFoundException: ScannerFileTest.java (系统找不到指定的文件。)
这样的错误。一直找不到指定的文件。
public class ScannerFileTest {
public static void main(String[]args) throws Exception
{
{
Scanner sc =new Scanner(new File("ScannerFileTest.java"));
System.out.println("ScannerFileTest.java文件内容容下:");
while(sc.hasNextLine())
{
System.out.println(sc.nextLine());
}
}
}
}
调试了一下发现在Scanner sc =new Scanner(new File(“ScannerFileTest.java”));中改一下路径就行
Scanner sc =new Scanner(new File(“D:/eclipse-wenjian/pri/src/Key/ScannerFileTest.java”));
这样就可以了。