从包含大量文件的zip文件中提取1个文件的最快方法是什么? [英] What is the fastest way to extract 1 file from a zip file which contain a lot of file?

查看:195
本文介绍了从包含大量文件的zip文件中提取1个文件的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了 java.util.zip 包,它是太慢了。

I tried the java.util.zip package, it is too slow.

然后我找到了 LZMA SDK 7z jbinding 但他们也缺少一些东西。
LZMA SDK没有提供一种如何使用的文档/教程,这是非常令人沮丧的。没有javadoc。

Then I found LZMA SDK and 7z jbinding but they are also lacking something. The LZMA SDK does not provide a kind of documentation/tutorial of how-to-use, it is very frustrating. No javadoc.

虽然7z jbinding不提供仅提取1个文件的简单方法,但它只提供了提取zip文件的所有内容的方法。此外,它没有提供指定放置解压缩文件的位置的方法。

While the 7z jbinding does not provide a simple way to extract only 1 file, however, it only provide way to extract all the content of the zip file. Moreover, it does not provide a way to specify a location to place the unzipped file.

有任何想法吗???

推荐答案

你的代码是什么使用 java.util.zip 看起来和你处理的zip文件有多大?

What does your code with java.util.zip look like and how big of a zip file are you dealing with?

我'我能够在大约一秒钟内从一个200MB的zip文件中提取一个4MB的条目,大约一秒钟内有1,800个条目:

I'm able to extract a 4MB entry out of a 200MB zip file with 1,800 entries in roughly a second with this:

OutputStream out = new FileOutputStream("your.file");
FileInputStream fin = new FileInputStream("your.zip");
BufferedInputStream bin = new BufferedInputStream(fin);
ZipInputStream zin = new ZipInputStream(bin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
    if (ze.getName().equals("your.file")) {
        byte[] buffer = new byte[8192];
        int len;
        while ((len = zin.read(buffer)) != -1) {
            out.write(buffer, 0, len);
        }
        out.close();
        break;
    }
}

这篇关于从包含大量文件的zip文件中提取1个文件的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆