我正嘗試在這種情況下使用intelij中的文件txt文件。我發現,如果我分辨出整個文件路徑如使用intelij中的文件IDEA
"C:\\Users\\benji\\java\\Project\\files\\newfile.txt"
作品,但如果我嘗試
"files/newfile.txt"
我得到這個例外
Exception in thread "main" java.nio.file.NoSuchFileException: files\newfile.txt
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileCopy.copy(WindowsFileCopy.java:99)
at sun.nio.fs.WindowsFileSystemProvider.copy(WindowsFileSystemProvider.java:278)
at java.nio.file.Files.copy(Files.java:1274)
at Main.main(Main.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
該文件是存在的,我希望有人會能夠擺脫一些光線謝謝你。
我建議你檢查你的工作目錄運行中的配置。我建議你打印出'System.out.println(System.getProperty(「user.dir」))' –
或類似的'System.out.println(new File(「」)。getAbsolutePath())' –
您。你在Windows下幫了我很多=) –