码迷,mamicode.com
首页 > 其他好文 > 详细

Zip加密解密

时间:2015-05-14 20:08:47      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

Zip加密解密方法:

1、winzipaes http://blog.csdn.net/zhyh1986/article/details/7724229

2、zip4j http://blog.csdn.net/zhyh1986/article/details/7921376

3、JDK的zip包

4、Apache的zip

package com.xqx.zip;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.io.ZipInputStream;
import net.lingala.zip4j.model.FileHeader;

public abstract class Test {
    public static void main(String[] args) throws IOException, ZipException {
        ZipFile zip = new ZipFile("C:\\***\\***.zip");//待解压文件
        zip.setPassword("****");//密钥
        List<FileHeader> fileHeaderList = zip.getFileHeaders();  
        for (int i = 0; i < fileHeaderList.size(); i++) {  
            FileHeader h = fileHeaderList.get(i);
            ZipInputStream in = zip.getInputStream(h);
            File file = new File("C:\\***\\"+h.getFileName());
            if(!file.exists()) {
                file.createNewFile();
            }
            FileOutputStream os = new FileOutputStream(file);
            int readLen = -1;  
            byte[] buff = new byte[4096];  
              
            while ((readLen = in.read(buff)) != -1) {
                os.write(buff, 0, readLen);  
            }  
            os.close();  
            os = null;  
            in.close();  
            in = null; 
        }
    }
}

Zip加密解密

标签:

原文地址:http://www.cnblogs.com/XueRong-7/p/4503990.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!