Java Unzip to Folder unzip(String sZip)

Here you can find the source of unzip(String sZip)

Description

Unzip file Zip (terkompresi)

License

Open Source License

Parameter

Parameter Description
sZip Nama file zip

Declaration

public static void unzip(String sZip) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    /**//from   w ww  .  j a  va  2 s .  c o m
     * Unzip file Zip (terkompresi)
     * @param sZip Nama file zip
     */
    public static void unzip(String sZip) {
        byte[] buf = new byte[1024];

        try {
            // Membuka file Zip
            ZipInputStream zin = new ZipInputStream(new FileInputStream(
                    sZip));

            ZipEntry ze;
            // Iterasi dan mendapatkan file
            while ((ze = zin.getNextEntry()) != null) {
                FileOutputStream out = new FileOutputStream(ze.getName());
                int len;
                // Transfer byte dari file Zip ke output file
                while ((len = zin.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
                // Bersihkan resource
                out.close();
                System.out.println("Unzip " + ze.getName() + " [ok]");
            }

            // Bersihkan resource
            zin.close();

        } catch (IOException ex) {
            System.err.println(ex.getMessage());
        }
    }
}

Related

  1. unzip(String sourceFile, String destDir)
  2. unzip(String sourceFile, String toDir)
  3. unzip(String sourceFileName, String destPath)
  4. unzip(String sourceZip, String targetDirectory)
  5. unzip(String src, String dest, PrintStream stream)
  6. unzip(String toUnpackName)
  7. unzip(String zip, String dest)
  8. unzip(String zip, String folder)
  9. unzip(String zip, String path)