Here you can find the source of unzipArchive(File archive, File outputDir)
public static boolean unzipArchive(File archive, File outputDir)
//package com.java2s; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class Main { public static boolean unzipArchive(File archive, File outputDir) { boolean result = false; ZipFile zipfile;//from w w w. j av a2 s .c o m try { zipfile = new ZipFile(archive); for (Enumeration e = zipfile.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); unzipEntry(zipfile, entry, outputDir); } result = true; } catch (IOException e1) { // ignore } return result; } private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return; } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } BufferedInputStream inputStream = new BufferedInputStream( zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream( new FileOutputStream(outputFile)); try { byte[] buf = new byte[1024]; int len; while ((len = inputStream.read(buf)) > 0) { outputStream.write(buf, 0, len); } } finally { outputStream.close(); inputStream.close(); } } private static void createDir(File dir) throws IOException { if (!dir.mkdirs()) throw new IOException("Can not create dir " + dir); } }