我收到以下例外情況。掃描儀無線路發現異常
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