我試圖去我的計算機中的一些文本文件,但我不斷得到這個異常,雖然路徑是正確的,該文件存在。 這裏是我的代碼:FileNotFoundException雖然文件存在
public static void main(String[] args) throws IOException {
File wordFile = new File("D:\\IDC\\Stuff\\wordList.txt");
RandomAccessFile wordsList = new RandomAccessFile(wordFile, "rw");
System.out.println(wordFile.exists());
}
錯誤:
Exception in thread "main" java.io.FileNotFoundException: D:\IDC\Stuff\wordList.txt (The filename, directory name, or volume label syntax is incorrect)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:243)
at WordChecker.main(WordChecker.java:12)
你試圖打印帶有'的System.out.println的wordFile的絕對路徑(wordFile .getAbsolutePath())'?如果不是,請嘗試複製文件資源管理器中最後一條語句的輸出以檢查路徑是否存在。此外,您是否檢查過您有權讀取和寫入所需的文件? – Laurent
我的賭注是''wordList.txt.txt「'作爲真正的文件名。 @ Ohad121你檢查過你的文件名是你認爲的嗎?沒有隱藏文件擴展名? – Tom
你可以在Windows中打開文件嗎?看起來更像是一個Windows錯誤,而不是找不到文件的錯誤。 –