首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java生产压缩包的步骤

2013-12-04 
Java生产压缩包的方法commons-compress-1.5.jar//将byte数组,压缩为zip转为流输出ZipArchiveOutputStream

Java生产压缩包的方法
commons-compress-1.5.jar

//将byte数组,压缩为zip转为流输出
ZipArchiveOutputStream zos =(ZipArchiveOutputStream)new ArchiveStreamFactory().createArchiveOutputStream("zip", response.getOutputStream());
for (int i=0; i<fileList().size(); i++){
FileDTO item = dto.getFileList().get(i);
ZipArchiveEntry ze =new ZipArchiveEntry(item.getFileName());
zos.putArchiveEntry(ze);
//file
ByteArrayInputStream bais = new ByteArrayInputStream(item.getFileBytes());
IOUtils.copy(bais, zos);
bais.close();
}
zos.closeArchiveEntry();
zos.close();

热点排行