Here you can find the source of unzip(File src, File target)
Parameter | Description |
---|---|
src | a parameter |
target | a parameter |
public static void unzip(File src, File target) throws IOException
//package com.java2s; /*/*from w w w . jav a 2 s. co m*/ * z2env.org - (c) ZFabrik Software KG * * Licensed under Apache 2. * * www.z2-environment.net */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class Main { private static final int UNZIP_BUFFER = 64 * 1024; /** * unzip a file to a folder * * @param src * @param target */ public static void unzip(File src, File target) throws IOException { InputStream in = new FileInputStream(src); ZipInputStream zi = new ZipInputStream(in); try { String fn; ZipEntry ze; File f; OutputStream out; int l; byte[] buffer = new byte[UNZIP_BUFFER]; while ((ze = zi.getNextEntry()) != null) { fn = ze.getName(); if (fn.endsWith("/")) { // its a folder f = new File(target, fn.substring(0, fn.length() - 1)); f.mkdirs(); } else { // it's a regular file f = new File(target, fn); f.getParentFile().mkdirs(); out = new FileOutputStream(f); try { while ((l = zi.read(buffer)) >= 0) { out.write(buffer, 0, l); } } finally { out.close(); } } } } finally { zi.close(); } } }