Tags

package zip;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;

public class UnZip {

	static final int BUFFER = 2048;

	public UnZip(String input)	{
		try {
	         BufferedOutputStream dest = null;
	         BufferedInputStream is = null;
	         ZipEntry entry;
	         java.util.zip.ZipFile zipfile = new java.util.zip.ZipFile(input);
	         Enumeration e = zipfile.entries();
	         while(e.hasMoreElements()) {
	            entry = (ZipEntry) e.nextElement();
	            System.out.println("Extracting: " +entry);
	            is = new BufferedInputStream(zipfile.getInputStream(entry));
	            int count;
	            byte data[] = new byte[BUFFER];
	            FileOutputStream fos = new FileOutputStream(entry.getName());
	            dest = new BufferedOutputStream(fos, BUFFER);
	            while ((count = is.read(data, 0, BUFFER))
	              != -1) {
	               dest.write(data, 0, count);
	            }
	            dest.flush();
	            dest.close();
	            is.close();
	         }
	      } catch(Exception e) {
	         e.printStackTrace();
	      }

	}

	public static void main(String[] args) {
		String input 	= ".\\output\\compress.zip";
		UnZip app = new UnZip(input);
	}
}

Reference: http://java.sun.com/developer/technicalArticles/Programming/compression/
Advertisements