gpt4 book ai didi

java - 您如何在 Java 中解压缩拆分卷 zip?

转载 作者:行者123 更新时间:2023-12-04 17:40:52 30 4
gpt4 key购买 nike

我需要重新组装一个 100 部分的 zip 文件并提取内容。我尝试在输入流中简单地将 zip 卷连接在一起,但这不起作用。任何建议,将不胜感激。

谢谢。

最佳答案

这是您可以开始的代码。它从多卷 zip 存档中提取单个文件条目:

package org.test.zip;

import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.SequenceInputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {

public static void main(String[] args) throws IOException {
ZipInputStream is = new ZipInputStream(new SequenceInputStream(Collections.enumeration(
Arrays.asList(new FileInputStream("test.zip.001"), new FileInputStream("test.zip.002"), new FileInputStream("test.zip.003")))));
try {
for(ZipEntry entry = null; (entry = is.getNextEntry()) != null; ) {
OutputStream os = new BufferedOutputStream(new FileOutputStream(entry.getName()));
try {
final int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
for(int readBytes = -1; (readBytes = is.read(buffer, 0, bufferSize)) > -1; ) {
os.write(buffer, 0, readBytes);
}
os.flush();
} finally {
os.close();
}
}
} finally {
is.close();
}
}
}

关于java - 您如何在 Java 中解压缩拆分卷 zip?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8116443/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com