Here you can find the source of unzipFile(String zipFilePath, String targetPath)
public static void unzipFile(String zipFilePath, String targetPath)
//package com.java2s; /*/* w w w . ja v a 2 s.co m*/ * Copyright 2010-2011 ESunny.com All right reserved. This software is the confidential and proprietary information of * ESunny.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only * in accordance with the terms of the license agreement you entered into with ESunny.com. */ import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class Main { public static void unzipFile(String zipFilePath, String targetPath) { try { File zipFile = new File(zipFilePath); InputStream is = new FileInputStream(zipFile); ZipInputStream zis = new ZipInputStream(is); ZipEntry entry = null; while ((entry = zis.getNextEntry()) != null) { String zipPath = entry.getName(); try { if (entry.isDirectory()) { File zipFolder = new File(targetPath + File.separator + zipPath); if (!zipFolder.exists()) { zipFolder.mkdirs(); } } else { File file = new File(targetPath + File.separator + zipPath); if (!file.exists()) { File pathDir = file.getParentFile(); pathDir.mkdirs(); file.createNewFile(); } FileOutputStream fos = new FileOutputStream(file); int bread; while ((bread = zis.read()) != -1) { fos.write(bread); } fos.close(); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } zis.close(); is.close(); } catch (Exception e) { e.printStackTrace(); } } public static void unzipFile(byte[] content, String targetPath) { try { InputStream is = new ByteArrayInputStream(content); ZipInputStream zis = new ZipInputStream(is); ZipEntry entry = null; while ((entry = zis.getNextEntry()) != null) { String zipPath = entry.getName(); try { if (entry.isDirectory()) { File zipFolder = new File(targetPath + File.separator + zipPath); if (!zipFolder.exists()) { zipFolder.mkdirs(); } } else { File file = new File(targetPath + File.separator + zipPath); if (!file.exists()) { File pathDir = file.getParentFile(); pathDir.mkdirs(); file.createNewFile(); } FileOutputStream fos = new FileOutputStream(file); int bread; while ((bread = zis.read()) != -1) { fos.write(bread); } fos.close(); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } zis.close(); is.close(); } catch (Exception e) { e.printStackTrace(); } } }