我得到的 URL 如下:
String jarFilePath = getClass().getProtectionDomain().getCodeSource().getLocation()
这将为我提供 jar 文件的完整路径。现在,如何向上跳转一个文件夹并向其附加其他路径?例如,如果 jarFilePath 类似于:
c:/path/to/jar/file.jar
我想向上跳转一个文件夹并附加另一个相对路径,如下所示:
c:/path/to/resources/path/to/resources/
文件夹 resources 和 jar 位于文件系统中的同一目录级别。
最佳答案
File f = new File("C:/path/to/jar/file.jar");
File dest = new File(f.getParentFile().getParentFile(), "resources/path/to/resources");
关于java - 在 Java 中,在 URL 中向上跳转一个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24614922/