문제

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)
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top