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; } } }
时间: 2024-10-22 07:38:32