用 appache 的 commons-compress-1.9.jar 压缩zip包
2014-11-07 10:16
393 查看
用 appache 的 commons-compress-1.9.jar 压缩zip包
jar包下载路径:http://commons.apache.org/proper/commons-compress/download_compress.cgi
jar包下载路径:http://commons.apache.org/proper/commons-compress/download_compress.cgi
public static void main(String[] args) { ZipArchiveOutputStream zipOutput = null; try { String folderPath = "d:\\测试文件夹"; File zipFile = new File("d:\\demo.zip"); zipOutput = (ZipArchiveOutputStream) new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, new FileOutputStream(zipFile)); zipOutput.setEncoding("UTF-8"); zipOutput.setUseZip64(Zip64Mode.AsNeeded); File[] files = new File(folderPath).listFiles(); for(File file : files){ InputStream in = null; try { in = new FileInputStream(file); ZipArchiveEntry entry = new ZipArchiveEntry(file, file.getName());//zipOutput.createArchiveEntry(logFile, logFile.getName()); zipOutput.putArchiveEntry(entry); IOUtils.copy(in, zipOutput); zipOutput.closeArchiveEntry(); }finally{ if(in != null){ try { in.close(); } catch (Exception e) { } } } } zipOutput.finish(); zipOutput.close(); }catch(Exception e){ if(zipOutput != null){ try { zipOutput.close(); } catch (Exception e1) { } } throw e; } }文章出处:http://blog.csdn.net/m13321169565/article/details/8085921
相关文章推荐
- Apache Commons Compress 压缩zip
- 使用commons-compress.jar压缩ZIP文件
- 使用commons-compress操作zip文件(压缩和解压缩)
- .NET中zip的压缩和解压——SharpCompress插件的使用
- 通过 apache.commons.compress 压缩和下载文件
- 用commons-compress工具压缩文件夹成tar文件时,剔除所属目录树
- 使用commons-compress操作zip文件(压缩和解压缩)
- Java压缩类库的使用-4.Apache commons compress中的打包、压缩类库
- 使用commons-compress操作zip文件(压缩和解压缩)
- linux 压缩工具之比较 (gzip,zip,bzip2,lzma,compress)
- apache.commons.compress 压缩,解压
- .NET中zip的压缩和解压——SharpCompress
- 黄聪:.NET中zip的压缩和解压——SharpCompress
- Apache commons compress中的打包、压缩类库
- 使用commons-compress操作zip文件(压缩和解压缩)
- linux下常用压缩(compress ,gz ,bzip2,xf)命令和打包命令(tar,zip)详解
- .NET中zip的压缩和解压——SharpCompress
- PhalApi-Zip -- 压缩文件处理类
- zip,gzip压缩命令
- 使用blowery.Web.HttpCompress.dll对aspx压缩