我在运行时得到一个 jar 文件 url 为:
jar:file:///C:/proj/parser/jar/parser.jar!/test.xml
如何将其转换为有效路径:
C:/proj/parser/jar/parser.jar.
我已经尝试过使用 File(URI)
、getPath()
、getFile()
都是徒劳的。
最佳答案
如果 MS-Windows 不被前导斜杠冒犯的话,这可能会成功:
final URL jarUrl =
new URL("jar:file:/C:/proj/parser/jar/parser.jar!/test.xml");
final JarURLConnection connection =
(JarURLConnection) jarUrl.openConnection();
final URL url = connection.getJarFileURL();
System.out.println(url.getFile());
关于java - 如何从 jar : URL containing a "!" and a specific file in the jar? 中获取 jar URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/402683/