zip 包解压缩  记录

zip 包解压缩 

ZipInputStream zipInput = new ZipInputStream(inputStream, Charset.forName("GBK"));
                //读取一个目录
                ZipEntry nextEntry = zipInput.getNextEntry();
                String outPath = appConfig.getTmpPath() + System.currentTimeMillis() + File.separator;
                File outFile = new File(outPath);
                if (!outFile.exists()) {
                    outFile.mkdirs();
                }
                //不为空进入循环
                while (nextEntry != null) {
                    String name = nextEntry.getName();
                    File file = new File(outPath + File.separator + name);
                    fileProber(file);
                    //如果是目录,创建目录
                    if (name.endsWith("/")) {
                        file.mkdirs();
                    } else {
                        file.createNewFile();
                        //文件则写入具体的路径中
                        FileOutputStream fileOutputStream = new FileOutputStream(file);
                        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
                        int n;
                        byte[] bytes = new byte[1024];
                        while ((n = zipInput.read(bytes)) != -1) {
                            bufferedOutputStream.write(bytes, 0, n);
                        }
                        //关闭流
                        bufferedOutputStream.close();
                        fileOutputStream.close();
                    }
                    //关闭当前
                    zipInput.closeEntry();
                    //读取下一个目录,作为循环条件
                    nextEntry = zipInput.getNextEntry();
                }
 public static void fileProber(File dirFile) throws Exception {
        File parentFile = dirFile.getParentFile();
        if (!parentFile.exists()) {
            fileProber(parentFile);
            parentFile.mkdirs();
        }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值