Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ZipInputStream does not read comments



Has anybody out there ever successfully used ZipInputStream (or JarInputStream) to read the comments associated with each Zip entry in a zip file? When I use ZipFile I have no problem, but when I use ZipInputStream, the entries' comments are always null.

Here is a test program using ZipFile that works:

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ZipTest {


public ZipTest(File file) throws IOException {
ZipFile zip = new ZipFile(file);
Enumeration entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
System.out.println(entry.getName() + ": " + entry.getComment());
}
zip.close();
}


public static void main(String[] args) {
try {
new ZipTest(new File(args[0]));
} catch (IOException exc) {
System.err.println(exc);
}
}
}

And here is a test program using ZipInputStream that does not work:

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class ZipTest {


public ZipTest(File file) throws IOException {
InputStream in = new BufferedInputStream(new FileInputStream(file));
ZipInputStream zip = new ZipInputStream(in);
ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
System.out.println(entry.getName() + ": " + entry.getComment());
zip.closeEntry();
}
zip.close();
}


public static void main(String[] args) {
try {
new ZipTest(new File(args[0]));
} catch (IOException exc) {
System.err.println(exc);
}
}
}

Thanks,
Geoff
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.