我正在尝试使用类路径访问文件,如下所示:
String path = getClass().getProtectionDomain().getCodeSource()
.getLocation().toString();
File test = new File(path);
File table = new File(test, "testFile.xlsx");
我这样做是因为我需要创建一个 Jar,如果它在同一个文件夹中,它将读取和写入该文件。
我收到此错误:
java.io.FileNotFoundException: "myFilepath" (The filename, directory name, or volume label syntax is incorrect)
如果我将 myFilepath 复制并粘贴到文件浏览器中,它会显示我的文件。有人看到我做错了什么,或者我可以改进我的方法吗?