Why ContextClassLoader returns path with exclamation character?

送分小仙女□ 提交于 2019-12-05 07:49:53

It means whatever comes after the ! is inside the JAR file.

In case of myjarresource.jar!/conf/configuration.xml, open up myjarresource.jar using a compression utility such as 7-zip and you will see that it contains conf/configuration.xml.

In the JarURLConnection javadoc , the syntax of a JAR URL is described:

The syntax of a JAR URL is: jar:!/{entry}

So '!' indicates that you 'enter' the java archive.

Edit: I believe that you cannot do File file=new File(url.toURI()) because of the ":" which appears twice in the generated URI and is not compliant with the URI specifications(chapter 2.2 and 3) therefore this is rejected in the File ctor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!