a
554325746@qq.com
2020-01-02 e52632329ef8342a2f692bf58184fc54db3d2b4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.basic.security.utils;
 
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
 
public class ZipUtil {
    public static boolean unpackZip(String zipname, String path) {
        InputStream is;
        ZipInputStream zis;
        try {
            String filename;
            is = new FileInputStream(path + zipname);
            zis = new ZipInputStream(new BufferedInputStream(is));
            ZipEntry ze;
            byte[] buffer = new byte[1024];
            int count;
 
            while ((ze = zis.getNextEntry()) != null) {
                filename = ze.getName();
 
                // Need to create directories if not exists, or
                // it will generate an Exception...
                if (ze.isDirectory()) {
                    File fmd = new File(path + filename);
                    fmd.mkdirs();
                    continue;
                }
 
                FileOutputStream fout = new FileOutputStream(path + filename);
 
                while ((count = zis.read(buffer)) != -1) {
                    fout.write(buffer, 0, count);
                }
 
                fout.close();
                zis.closeEntry();
            }
 
            zis.close();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
 
        return true;
    }
}