May 26

Java provides the ZipInputStream class for reading from a zip file. Heres a general example of its usage

File file = new File("my.zip");
ZipInputStream zin = new ZipInputStream(new FileInputStream(file));
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
   String filename = ze.getName();
   if (!ze.isDirectory()) {
        // Read file contents from 'zin'
        // For example you could read from zin and write it to a FileOutputStream
        // http://helpdesk.objects.com.au/java/how-do-i-copy-one-stream-to-another-using-java
   }
   zin.closeEntry();
}
zin.close();

The same can be used to read the contents of a jar file.

written by objects \\ tags: , , , , ,