【发布时间】:2015-06-15 19:19:02
【问题描述】:
我正在尝试访问计算机中的某个文本文件,但我不断收到此异常,尽管路径正确且文件存在。 这是我的代码:
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.getAbsolutePath())打印wordFile的绝对路径吗?如果没有,请尝试在文件资源管理器中复制最后一条语句的输出,以检查路径是否存在。此外,您是否检查过您是否具有读取和写入所需文件的权限? -
我赌
"wordList.txt.txt"是真实的文件名。 @Ohad121 你检查过你的文件名是你认为的吗?没有隐藏文件扩展名? -
你能在windows中打开文件吗?看起来更像是 Windows 错误,而不是文件未找到错误。
-
我现在试试这个,但还是一样。我拥有该文件的权限,因为我创建了它并且我是计算机的管理员。我试图将文件移动到 eclips 的项目文件夹中,现在我只编写文件 nae 而没有像“wordList.txt”这样的整个路径,并且每次运行程序时它都会创建一个新文件,而不是从中读取。
标签: java file path filenotfoundexception randomaccessfile