如何将“jar:file”URI转换为Jar文件的路径?

时间:2011-11-04 18:30:08

标签: java uri

如何从jar:file:/C:/Program%20Files/test.jar!/foo/bar转到指向File的{​​{1}}?

1 个答案:

答案 0 :(得分:11)

以下代码适用于我(基于How do I get just the jar URL from a jar: URL containing a "!" and a specific file in the jar?):

URL url = new URL("jar:file:/C:/Program%20Files/test.jar!/foo/bar");
JarURLConnection connection = (JarURLConnection) url.openConnection();
File file = new File(connection.getJarFileURL().toURI())