JAVA ZIP解压工具类


	JAVA ZIP解压工具类
[编程语言教程]

 1 import java.io.*;
 2 import java.nio.charset.Charset;
 3 import java.util.Enumeration;
 4 import java.util.zip.ZipEntry;
 5 import java.util.zip.ZipFile;
 6 
 7 public class ZipUtil {
 8 
 9     /**
10      * zipFile:待解压的zip文件
11      * destDir:指定的解压目录
12      */
13     public static void unZipFiles(File zipFile, String destDir) throws IOException {
14         File pathFile = new File(destDir);
15         if (!pathFile.exists()) {
16             pathFile.mkdirs();
17         }
18         ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK"));
19         for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
20             ZipEntry entry = (ZipEntry) entries.nextElement();
21             InputStream in = zip.getInputStream(entry);
22             String outPath = (destDir + File.separator + entry.getName()).replaceAll("\", "/");
23             File file = new File(outPath.substring(0, outPath.lastIndexOf(‘/‘)));
24             if (!file.exists()) {
25                 file.mkdirs();
26             }
27             if (new File(outPath).isDirectory()) {
28                 continue;
29             }
30             OutputStream out = new FileOutputStream(outPath);
31             byte[] buf1 = new byte[1024];
32             int len;
33             while ((len = in.read(buf1)) > 0) {
34                 out.write(buf1, 0, len);
35             }
36             in.close();
37             out.close();
38         }
39     }
40 
41 }
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » JAVA ZIP解压工具类