Johan
Johan

Reputation: 3819

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?

Upvotes: 0

Views: 8666

Answers (2)

King Natsu
King Natsu

Reputation: 463

Use File.separator instead of "/" in any project.

Upvotes: 8

nitind
nitind

Reputation: 20003

Use a forward slash, '/', as it's the one that will work in file paths for both Windows and non-Windows platforms.

Upvotes: 2

Related Questions