Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从jar文件获取相对路径_Java_Path_Relative Path - Fatal编程技术网

Java 从jar文件获取相对路径

Java 从jar文件获取相对路径,java,path,relative-path,Java,Path,Relative Path,我试图在Ubuntu中找到一个特殊的路径,相对于当前的jar文件。 在Windows中,它可以正常工作: String jarPath = Configuration.class.getProtectionDomain().getCodeSource().getLocation().getPath(); File f = new File(jarPath+"/../../configurationFile.xml"); 然而,在Linux中,我总是得到jar文件,但我不能将两个目录返回到con

我试图在Ubuntu中找到一个特殊的路径,相对于当前的jar文件。 在Windows中,它可以正常工作:

String jarPath = Configuration.class.getProtectionDomain().getCodeSource().getLocation().getPath();
File f = new File(jarPath+"/../../configurationFile.xml");
然而,在Linux中,我总是得到jar文件,但我不能将两个目录返回到configurationFile.xml

/some/directory/where/xml/is/located/xyz.jar/configurationFile.xml: Not a directory
然而,如果我这样做

pwd /some/directory/where/xml/is/located/xyz.jar/../../
它工作没有任何问题

我做错了什么


我想不出来。

只使用路径中的目录。
确定jar文件的路径后,提取其目录的路径并仅使用目录。

尝试使用file.separator而不是斜杠:
新文件(file.separator+“home”+file.separator+“某处”)非常感谢!我会试试的。嗨,这很有效。我分割了路径并按我需要的方式重新连接,现在它可以工作了!非常感谢你。