我想从 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 进度)
只能解压一个文件。
那么如何使用纯 Java 解压缩 7-zip 字节流呢?
有大佬解决吗?
抱歉我的英语不好,我在网上等待你的回答。
最佳答案
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();
关于java - 如何从 Java 中的 7-zip 流中提取文件而不将其存储在硬盘上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21897286/