Here you can find the source of unzip(File zipFileName, File targetDir)
public static void unzip(File zipFileName, File targetDir) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileFilter; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class Main { public static void unzip(File zipFileName, File targetDir) throws IOException { unzip(zipFileName, targetDir, new FileFilter() { public boolean accept(File file) { return true; }//w w w . j av a 2 s . c om }); } public static void unzip(File zipFileName, File targetDir, FileFilter filter) throws IOException { ZipFile zipFile = new ZipFile(zipFileName); Enumeration enumeration = zipFile.entries(); while (enumeration.hasMoreElements()) { ZipEntry entry = (ZipEntry) enumeration.nextElement(); String name = entry.getName(); if (filter.accept(new File(targetDir, name))) { if (entry.isDirectory()) { new File(targetDir, name).mkdirs(); } else { File targetFile = new File(targetDir, name); targetFile.getParentFile().mkdirs(); InputStream source = zipFile.getInputStream(entry); FileOutputStream fileOutputStream = new FileOutputStream(targetFile); copyAndClose(source, fileOutputStream, false); } } } zipFile.close(); } public static void copyAndClose(InputStream source, OutputStream dest, boolean buffered) throws IOException { copy(source, dest, buffered); source.close(); dest.close(); } public static void copy(InputStream source, OutputStream dest, boolean buffered) throws IOException { //TODO: buffering is disabled until file truncation issue is resolved buffered = false; if (buffered) { source = new BufferedInputStream(source); dest = new BufferedOutputStream(dest); } int bytesRead; byte[] buffer = new byte[1024]; while ((bytesRead = source.read(buffer)) >= 0) { dest.write(buffer, 0, bytesRead); } } }