简体   繁体   中英

java.io.FileNotFoundException: .. (No such file or directory)

I had developed a Java project correctly working on Eclipse under Windows OS. Then I wanted to switch to Ubuntu. I just took the full workspace folder (included all resources file required for the running) from Windows and imported it in the Ubuntu's Eclipse.

Most surprisingly I get the following exception:

[ Test ] ERROR: unable to create myClass object. 
Check your implementation requirements!
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at Test.main(Test.java:183)
Caused by: java.io.FileNotFoundException: raw\file1.txt (No such file or directory)
...

but such directory and such file do actually exist in the current path.

Why may this happen?

在任何项目中都使用File.separator而不是"/"

使用正斜杠“ /”,因为它在Windows和非Windows平台的文件路径中都可以使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM