Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

jarURL.openStream() throws *IOException: no entry name specified*

843790Jun 8 2006 — edited Apr 14 2010
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 12 2010
Added on Jun 8 2006
3 comments
1,628 views