网上可以搜到一些关类似代码,不过大多以生成压缩文件为主,生成加密文件的也有,不过即压缩又加密的比较少。在此给大家提供一个jar,主要实现了将文件夹压缩成带密码的zip格式文件,并提供解密方法。主要的两个函数分别为EncryptZipFile和DecryptZipFile函数。
/**
* 生成带密码的ZIP压缩文件
* @param zipDir 待压缩文件路径* @param EncryptZipFile 生成压缩文件得存储路径
* @param password 压缩密码
* @return 成功返回1,失败为0
*/
public static int EncryptZipFile(String zipDir, String EncryptZipFile,String password)
/**
* 解压带密码的ZIP文件
* @param EncryptZipFile 待解压的加密压缩文件路径
* @param unZipDir 解压文件夹的存储路径
* @param password 解压密码
* @return 成功返回1,失败为0
*/
public static int DecryptZipFile(String EncryptZipFile, String unZipDir,String password)
调用方式如下:
import nochump.util.extend.*;
public class test {
public static void main(String[] args) {
//加密压缩
ZipFileWithPassword.EncryptZipFile("d://test", "d://test.zip", "1234");
//解密压缩
ZipFileWithPassword.DecryptZipFile("d://test.zip", "d://newTest", "1234");
}
}
目前只支持生成zip压缩格式的。Android也可以使用该JAR包。
本文介绍了一个Java库,它能够实现将文件夹压缩成带有密码保护的ZIP文件,并提供了相应的解密方法。库中包含两个关键函数:EncryptZipFile用于生成加密文件,DecryptZipFile用于解密文件。通过简单的调用示例演示了如何使用此库进行文件压缩和解压。
9962

被折叠的 条评论
为什么被折叠?



