use*_*817 12 java compression 7zip
我想从一个7-zip字节流中提取一些文件,它不能存储在硬盘上,所以我不能使用RandomAccessFile类,我已经阅读了sevenzipjbinding源代码,它还用一些封闭的源代码解压缩文件比如lib7-Zip-JBinding.so用其他语言写的.和官方包SevenZip的方法一样
SevenZip.Compression.LZMA.Decoder.Code(java.io.InputStream inStream,java.io.OutputStream outStream,long outSize,ICompressProgressInfo progress)
只能解压缩单个文件.
那么如何用纯Java解压缩7-zip字节流呢?
有人有解决方案吗?
抱歉我的英语不好,我在网上等你的答案.
SAN*_*NN3 11
Commons compress 1.6及以上版本支持操作7z格式.试试吧.
参考:
http://commons.apache.org/proper/commons-compress/index.html
样品:
SevenZFile sevenZFile = new SevenZFile(new File("test-documents.7z"));
SevenZArchiveEntry entry = sevenZFile.getNextEntry();
while(entry!=null){
System.out.println(entry.getName());
FileOutputStream out = new FileOutputStream(entry.getName());
byte[] content = new byte[(int) entry.getSize()];
sevenZFile.read(content, 0, content.length);
out.write(content);
out.close();
entry = sevenZFile.getNextEntry();
}
sevenZFile.close();
Run Code Online (Sandbox Code Playgroud)