Pregunta

Zip4j fails to open/extract gz files created in UNIX. 7Zip opens the file without any problem. The zip is not enrypted. Is there any option to be set(like host type) before reading the file headers in the file.

    File file   =   new File("D:/unziptest/i6163795A140507230411.dl.gz");

    try {
        System.out.println(file.length());

        ZipFile zipFile                 =   new ZipFile(file);
        if (!zipFile.isEncrypted()){
            if(zipFile.getFileHeaders()!=null){
                List<FileHeader> files  =   zipFile.getFileHeaders();
                for(FileHeader fileHeader : files){
                    if(fileHeader!=null){
                        System.out.println(fileHeader.getFileName());
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

Output

16388
net.lingala.zip4j.exception.ZipException: zip headers not found. probably not a zip file
    at net.lingala.zip4j.core.HeaderReader.readEndOfCentralDirectoryRecord(HeaderReader.java:122)
    at net.lingala.zip4j.core.HeaderReader.readAllHeaders(HeaderReader.java:78)
    at net.lingala.zip4j.core.ZipFile.readZipInfo(ZipFile.java:425)
    at net.lingala.zip4j.core.ZipFile.isEncrypted(ZipFile.java:722)
    at UnzipFile.main(UnzipFile.java:35)
¿Fue útil?

Solución

Zip and gzip are two different incompatible compression formats as described here. I don't have your original file to test with but you should have better luck with GZipInputStream.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top