Diliban B
Diliban B

Reputation: 19

Trying to read Split Zip File throws ZipException in zip4j

I am having a split zip file test_10G.zip.001 and test_10G.zip.002. I am trying to use isSplitArchive() Function from zip4j. But I am getting an exception saying Zip headers not found. Probably not a zip file .

import net.lingala.zip4j.exception.ZipException;

import java.io.File;
import java.io.IOException;

public class SplitZipMain {
    public static void main(String[] args) throws IOException {
        try (ZipFile splitZip1 = new ZipFile(new File("./test_10G.zip.001"))) {
            System.out.println(splitZip1.isSplitArchive());
        }
    }
}

Does zip4j support split zip files? I am using zip4j 2.11.5. The zip file is created using 7zip with volumes split as 10 mb.

Upvotes: 0

Views: 60

Answers (2)

Oleg Cherednik
Oleg Cherednik

Reputation: 18255

There're two ways of mark split zip (zip with multiple files):

  • PKWare - filename.zip, filename.z01, filename.z02
  • 7-Zip - filename.zip.001, filename.zip.002, filename.zip.003

zip4jvm lib supports both formats for reading.

To check if zip archive is split or not, you can check following snippet

Path zip = Paths.get("./test_10G.zip.001");
boolean split = !SrcZip.of(zip).isSolid();

To extract all files from the split zip, you can check following snippet

Path zip = Paths.get("./test_10G.zip.001");
Path destDir = Paths.get("/destination_dir");
UnzipIt.zip(zip).destDir(destDir).extract();

More examples you can find on the zip4jvm main page

Upvotes: 0

talex
talex

Reputation: 20544

Split archive have extensions z01, z02... zip.

Last one contains all metainfo. You need to check it.

Here is example from documentation.

Upvotes: 0

Related Questions