Apache Commons Compress 压缩zip
来源:互联网 发布:国际交流软件有哪些 编辑:程序博客网 时间:2024/05/21 09:54
1.序言
官网提供了一个例子,研究了一天才知怎么用。
2.版本
Apache Commons Compress1.12
3.官网例子
public class ScatterSample {ParallelScatterZipCreator scatterZipCreator = new ParallelScatterZipCreator();ScatterZipOutputStream dirs = ScatterZipOutputStream.fileBased(File.createTempFile("scatter-dirs", "tmp"));public ScatterSample() throws IOException {}public void addEntry(ZipArchiveEntry zipArchiveEntry, InputStreamSupplier streamSupplier) throws IOException {if (zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink())dirs.addArchiveEntry(ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, streamSupplier));elsescatterZipCreator.addArchiveEntry(zipArchiveEntry, streamSupplier);}public void writeTo(ZipArchiveOutputStream zipArchiveOutputStream)throws IOException, ExecutionException, InterruptedException {dirs.writeTo(zipArchiveOutputStream);dirs.close();scatterZipCreator.writeTo(zipArchiveOutputStream);}}
4.调用方式
public class ZipInputStream implements InputStreamSupplier{@Overridepublic InputStream get() {InputStream inputStream = null;try {inputStream = new FileInputStream(new File("f:/write.docx"));} catch (FileNotFoundException e) {e.printStackTrace();}return inputStream;}}
ScatterSample scatterSample = new ScatterSample();ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(new File("f:/test.zip"));ZipArchiveEntry entry = new ZipArchiveEntry("write.docx");entry.setMethod(ZipMethod.STORED.getCode());scatterSample.addEntry(entry, new ZipInputStream());scatterSample.writeTo(zipArchiveOutputStream);zipArchiveOutputStream.close();
5.说两句
这个是我的测试,要用的话,请自行整理出来,灵活调用,write.docx是我提前准备压缩进test.zip的文件,您需要事先准备该文件,test.zip是自动生成的,不用管。
0 0
- Apache Commons Compress 压缩zip
- Apache commons-compress ZIP打包
- 使用commons-compress.jar压缩ZIP文件
- apache.commons.compress zip压缩解压工具类完整版(使用递归支持无限文件夹的解压缩)
- 使用commons-compress操作zip文件(压缩和解压缩)
- Java 使用Apache commons-compress 解压zip文件
- Apache commons compress中的打包、压缩类库
- 通过 apache.commons.compress 压缩和下载文件
- Apache Commons Compress
- Apache Commons Compress
- Java压缩类库的使用-4.Apache commons compress中的打包、压缩类库
- 用Apache Commons Compress 產生tar.gz
- Unix/Linux压缩命令 bzip/bzip2/zip/compress/dd/cpio/
- Apache在Commons Compress简介和简单应用
- commons compress使用
- commons compress使用+ziji
- 用commons-compress工具压缩文件夹成tar文件时,剔除所属目录树
- 利用org.apache.tools.zip.* 压缩、解压
- Codeforces 400D. Dima and Bacteria【并查集+最短路】
- LinuxShell宝典 --- 判断与比较
- 升讯威ADO.NET增强组件(源码):送给喜欢原生ADO.NET的你
- ElasticSearch详解三之——查询
- MVC和MVP
- Apache Commons Compress 压缩zip
- ubuntu14.04安装hadoop 2.7.3
- Conversion to dalvik format failed with error 1
- 4513: [Sdoi2016]储能表
- Android动画-滚动小车
- MongoDB整合Spring 详细讲解(含代码)
- porting valgrind to arm platform
- C++进程间通信方法比较
- 最大似然估计(Maximum likelihood estimation)