Search code examples
javafileuriarchive

Get a File or URI object for a file inside an archive with Java?


is it possible to get a File or URI object for a file inside an archive with Java? (zip or jar archive)

Thanks Hemeroc.


Solution

  • The jar: protocol is a way to build a URI to a resource in a JAR archive:

    jar:http://www.example.com/bar/baz.jar!/path/to/file
    

    See the API docs for JarURLConnection: http://java.sun.com/javase/6/docs/api/java/net/JarURLConnection.html

    Between the jar: and !/ can be any URL, including a file: URL.