import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.zip.Zip64Mode;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.Zip64Mode;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
解决方案 »
- 删除list出错:attempt to create delete event with null entity
- hibernate原生sql语句的疑惑
- 2个字符串型数组,找其中相同的项
- 有多少人知道水晶易表?
- 怎么获取到数据库sql2000 事务日志中执行过sql语句( 查询 修改 删除 存储过程等)
- hibernate 分页 总是报错!
- 数据统计组件
- 100分请教下关于用户权限模块的设计与实现,谢谢。
- 用struts如何实现双提交按钮?
- 打算用jboss+mysql+jbuilder来开发j2ee项目,请各位给点意见,特别是建模和性能方面的,来者有分!!!!!!
- 关于水晶报表问题IReportAppFactory.openDocument(infoObject,0,java.util.Locale.US)挂起
- spring 中dao无法注入??
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
/**
* 压缩文件
* @param filePaths 存放文件物理路径的集合
* @param fileNames 文件的名称(和文件路径对应,可以是中文)
* @param outPath 压缩文件的输出路径(物理路径)
*/
public void reduceFile(List<String> filePaths, List<String> fileNames, String outPath) {
if (null != filePaths && filePaths.size() > 0 && null != fileNames && fileNames.size()== filePaths.size()) {
try {
OutputStream fileOutput = new FileOutputStream(outPath);
ZipOutputStream zipOutput = new ZipOutputStream(fileOutput);
for (int i = 0; i < filePaths.size(); i++) {
File file = new File(filePaths.get(i));
if (file.exists() && !file.isDirectory()) {
InputStream input = new FileInputStream(file);
ZipEntry entry = new ZipEntry(fileNames.get(i));
zipOutput.putNextEntry(entry);
int length = 0;
while ((length = input.read()) != -1) {
zipOutput.write(length);
}
input.close();
}
}
zipOutput.setEncoding("GBK");
zipOutput.flush();
zipOutput.closeEntry();
zipOutput.close();
fileOutput.flush();
fileOutput.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}