我收到以下例外情况。扫描仪无线路发现异常
java.util.NoSuchElementException:没有找到行
在写从文本文件阅读这需要更大的程序中,我得到这个错误,所以决定做一个测试。
Scanner scan = new Scanner(new File("restrictions.txt");
String s1 = scan.nextLine();
System.out.println(s1);
而且我仍然得到例外。我在文件名为restrictions.txt的文件夹中有一个文本文件,其中包含文本。我究竟做错了什么?
我也尝试了scan.next()而不是scan.nextLine()并得到这个异常:java.util.NoSuchElementException – gmaster
你确定该文件存在吗?尝试System.out.println(file.getAbsolutePath()+“”+ file.exists())并确保它在那里。 – chubbsondubs
我非常确定该文件存在,扫描程序初始化时没有出现异常,我尝试通过NetBeans和文件浏览器进行创建,但无论如何我都会检查。 – gmaster