Woozle Wuzzle
Minor ZipFile gotcha

java.util.zip.ZipFile and its subclass java.util.jar.JarFile has a minor gotcha when using getEntry(String); leading slashes are not ignored. For example:

    final JarFile jarFile = new JarFile("rt.jar");
    System.out.println(jarFile.getEntry("/java/lang/Object.class"));
    System.out.println(jarFile.getEntry("java/lang/Object.class"));

will return:

    null
    java/lang/Object.class

In general, this is not a big deal. But when manually parsing URLs (don't ask) such as:

    jar:file://rt.jar!/java/lang/Object.class

it can bite you in the butt.

Comments
Post a comment













Remember personal info?






Creative Commons License Unless otherwise expressly stated, all original material of whatever nature created by Rob Grzywinski and included in this weblog and any related pages, including the weblog's archives, is licensed under a Creative Commons License.