标签:
Java自带的库不支持压缩成多个压缩卷,找到了一个开源库 zip4j ,发现更好用 so easy
package com.jws.common.mail;
import java.io.File;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import org.apache.log4j.Logger;
public class MailZip4jService {
private MailZip4jService() {
}
private static class JiveGlobeHolder {
private static MailZip4jService instance = new MailZip4jService();
}
public static MailZip4jService getInstance() {
return JiveGlobeHolder.instance;
}
private final Logger log = Logger.getLogger(this.getClass());
/**
* zip4j压缩卷
* @param srcPath 压缩文件存放位置
* @param filePath 压缩文件
* @param size 分割文件大小
* @return
*/
public boolean presssureFile(String srcPath,File filePath,long size){
try {
ZipFile zipFile = new ZipFile(srcPath);
ZipParameters parameters = new ZipParameters();
zipFile.createZipFile(filePath, parameters,true, size);
return true;
}catch (ZipException e) {
log.error("【压缩文件】:压缩出现问题");
return false;
} catch (Exception e) {
log.error("【压缩文件】:文件异常");
return false;
}
}
}
标签:
原文地址:http://www.cnblogs.com/kimobolo/p/5121309.html