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

查看:28
本文介绍了使用 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天全站免登陆