I have some code (supplied below) which tries to read contents of a resource referred by a URL.
public class URLTest {
public static void main(String... args) throws Exception {
URL u = new URL(args[0]);
InputStream is = u.openStream();
// more code goes here:
}
}
If you create a jar file in /tmp/b.jar and run this program as shown below:
java pkg.URLTest
jar:file:/tmp/b.jar!/
it produces the following exception:
Exception in thread "main" java.io.IOException: no entry name specified
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:131)
at java.net.URL.openStream(URL.java:1007)
at pkg.URLTest.main(URLTest.java:20)
If you pass the argument as
jar:file:/tmp/b.jar!/c.jar then it opens a stream that points to c.jar which is embedded inside b.jar.
My question is, what is the motivation behind not allowing user to open a stream to jar:file:/tmp/b.jar!/ which according to the javadocs of JarURLConnection represents a JAR File?
Thanks,
Sahoo