使用Java解压缩多部分zip文件卷 [英] Unzipping a multi-part zip file volumes using Java

查看:116
本文介绍了使用Java解压缩多部分zip文件卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解压缩作为zip存档的一组文件.这不是一组zip文件,这是一个很大的zip文件,已根据大小要求将其分解为多个zip文件.

I need to unzip a set of files that are a zip archive. This isn't a set of zip files, this is one big zip file that has been broken up into multiple zip files based on a size requirement.

例如,如果您有一个2.5MB的zip文件,而您的邮件系统仅支持1MB的文件,则可以要求Zip创建3个最大1MB的文件.

For example if you have a 2.5MB zip file and your mail system only supports 1MB files, you can ask Zip to create 3 files of at most 1MB.

因此它创建了a.zip.001,a.zip.002,a.zip.003 ...不同的库对它们的命名不同,但是本质上它们都以相同的方式工作.

So it creates a.zip.001, a.zip.002, a.zip.003 ... different libraries name them differently but essentially they all work the same way.

如何在Java中解压缩此文件?看起来std中的压缩库似乎不支持这一点.

How do you unzip this in java? It doesn't look like the compression libs in std supports this.

谢谢.

推荐答案

尝试将所有文​​件串联为单个文件,然后解压缩单个文件.像这样:

Try to concatenate all the files into a single file and then extract the single file. Something like:

    File dir = new File("D:/arc");
    FileOutputStream fos = new FileOutputStream(new File(
            "d:/arc/archieve-full.zip"));
    FileInputStream fis = null;
        Set<String> files = new TreeSet<String>();
        for (String fname : dir.list()) {
            files.add(fname);
        }
        for (String fname : files) {
        try {
            fis = new FileInputStream(new File(dir.getAbsolutePath(), fname));
            byte[] b = new byte[fis.available()];
            fis.read(b);
            fos.write(b);
        } finally {
            if (fis != null) {
                fis.close();
            }
            fos.flush();
        }
    }
    fos.close();
    ZipFile zipFile = new ZipFile("d:/arc/archieve-full.zip");
    /*extract files from zip*/

更新:使用TreeSet对文件名进行排序,因为dir.list()不保证字母顺序.

Update: used a TreeSet to sort the file names, as dir.list() doesn't guarantee alphabetical order.

这篇关于使用Java解压缩多部分zip文件卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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