
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; /** * Unzip a zip file to specific destination. * @param source Zip File * @param destination Unzipped file path */ public static void decompress(File source, File destination) throws IOException { ZipInputStream zis = new ZipInputStream(new FileInputStream(source)); byte[] buffer = new byte[1024]; for (ZipEntry zip; (zip = zis.getNextEntry()) != null;) { File file = new File(destination, zip.getName()); if (zip.isDirectory()) { file.mkdir(); } else { FileOutputStream fos = new FileOutputStream(file); for (int length; (length = zis.read(buffer)) > 0;) { fos.write(buffer, 0, length); } fos.close(); } zis.closeEntry(); } zis.close(); }
This method can unzip a zip file source
Source argument is a source file path, destination for the final destination the file unzipped to.