|
@ -133,6 +133,44 @@ public class Zipper {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public File zipFileForAll(File unzipFile, String zipFileName, String pwd) throws ZipException {
|
|
|
//文件不存在时不压缩
|
|
|
if (!unzipFile.exists()) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
ZipParameters parameters = new ZipParameters();
|
|
|
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
|
|
|
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
|
|
|
if (!StringUtil.isEmpty(pwd)) {
|
|
|
parameters.setEncryptFiles(true);
|
|
|
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
|
|
|
parameters.setPassword(pwd.toCharArray());
|
|
|
}
|
|
|
|
|
|
File file = new File(zipFileName);
|
|
|
if (!file.exists()) {
|
|
|
file.getParentFile().mkdirs();
|
|
|
}
|
|
|
|
|
|
ZipFile zipFile = new ZipFile(zipFileName);
|
|
|
if (unzipFile.isDirectory()) {
|
|
|
// zipFile.addFolder(unzipFile, parameters);
|
|
|
File[] files = unzipFile.listFiles();
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
if (files[i].isDirectory()) {
|
|
|
zipFile.addFolder(files[i], parameters);
|
|
|
} else {
|
|
|
zipFile.addFile(files[i], parameters);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
zipFile.addFile(unzipFile, parameters);
|
|
|
}
|
|
|
|
|
|
return new File(zipFileName);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param zipFile 需要解压的文件名
|
|
|
* @param unzipDirectory 解压文件路径
|