Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 尽管文件存在,但FileNotFoundException_Java_File_Path_Filenotfoundexception_Randomaccessfile - Fatal编程技术网

Java 尽管文件存在,但FileNotFoundException

Java 尽管文件存在,但FileNotFoundException,java,file,path,filenotfoundexception,randomaccessfile,Java,File,Path,Filenotfoundexception,Randomaccessfile,我正在尝试获取计算机中的某个文本文件,但我不断获取此异常,尽管路径正确且文件存在。 这是我的密码: public static void main(String[] args) throws IOException { File wordFile = new File("‪D:\\IDC\\Stuff\\wordList.txt"); RandomAccessFile wordsList = new RandomAccessFile(wordFile, "rw");

我正在尝试获取计算机中的某个文本文件,但我不断获取此异常,尽管路径正确且文件存在。 这是我的密码:

    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)
线程“main”java.io.FileNotFoundException中的异常:‪D:\IDC\Stuff\wordList.txt(文件名、目录名或卷标语法不正确) 位于java.io.RandomAccessFile.open(本机方法) 位于java.io.RandomAccessFile。(RandomAccessFile.java:243) 在WordChecker.main(WordChecker.java:12)
您能重命名该文件吗?如果您从另一个位置复制了文件名,并且文件名中有不可见的字符,这会有所帮助。

当我复制您的代码并试图将其保存在Eclipse中时。我得到了下面的错误

我由此得出结论,虽然你的道路看起来‪D:\\IDC\\Stuff\\wordList.txt'但实际上不是。所以我所做的,只需键入这一行
File File File=new File(“D:\\IDC\\Stuff\\wordList.txt”)而不是从代码中复制它。它成功了。似乎您也从某个地方复制了它,对于编码问题,您遇到了问题

还有一点,您应该使用
System.getProperty(“file.separator”)
而不是\\或/如下所示

File wordFile = new File("‪D:" + System.getProperty("file.separator")
                + "IDC" + System.getProperty("file.separator") + "Stuff"
                + System.getProperty("file.separator") + "wordList.txt");
文件分隔符

分隔文件路径组件的字符。这在UNIX上是“/”,在Windows上是“\”


您是否尝试过使用
System.out.println(wordFile.getAbsolutePath())
打印wordFile的绝对路径?如果没有,请尝试复制文件资源管理器中最后一条语句的输出,以检查路径是否存在。此外,您是否已检查您是否具有读取和写入所需文件的权限?我打赌
“wordList.txt.txt”
是真正的文件名@Ohad121您是否检查过您的文件名是否与您认为的相同?没有隐藏的文件扩展名?能否在windows中打开该文件?看起来更像是windows错误,而不是文件未找到错误。我现在尝试此操作,但仍然相同。我拥有对该文件的权限,因为我创建了该文件,并且我是计算机管理员。我试图将文件移动到eclips的项目文件夹中,现在我只需编写文件nae,没有像“wordList.txt”这样的完整路径,每次运行程序时它都会创建一个新文件,而不是从中读取。哦,天哪,这是对的,在
D:\
之前有一个不可见的字符(我认为是
U+202A
)。