java.io.FileNotFoundException: ..(没有那个文件或目录)

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

我开发了一个 Java 项目,可以在 Windows OS 下正确地在 Eclipse 上运行。然后我想切换到Ubuntu。我刚刚从 Windows 中获取了完整的工作区文件夹(包括 运行 所需的所有资源文件)并将其导入到 Ubuntu 的 Eclipse 中。

最令人惊讶的是我得到以下异常:

[ 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)
...

但是这样的目录和这样的文件确实存在于当前路径中

为什么会发生这种情况?

使用正斜杠“/”,因为它适用于 Windows 和非 Windows 平台的文件路径。

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