why ZipFile(file, ZipFile.OPEN_READ) does not work for GZip

gzip, java, zip

Solution

As @Joachim_Sauer stated already, they are apples and plums.

Take a look at apache's compress, which can handle both (and more) compression/archive types. However, you need to do different implementations AND you have to figure out which implementation to use (whether you handle a zip or gzip file) on your own.

Problem

I am working on decompressing Zip archives. As there are two types of archives - Zip and GZip. I am using following ``` ZipFile zipFile = new ZipFile(file, ZipFile.OPEN_READ); ``` But it is giving following error for GZip types of archives ``` java.util.zip.ZipException: error in opening zip file at java.util.zip.ZipFile.open(Native Method) ``` This code is working fine for Zip compressed type archives, not for GZip Is there a way to use the above code as I have existing functionality using ZipFile across various functions.If I change ZipFile interface to ZipInputStream or GZipInputStream, then I need to change multiple things. EDIT : If incoming archives are of type Zip and GZip, do I need different implementation as per @Joachim Sauer's comment

Original source