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
Python's zipfile is a standard library module intended to manipulate ZIP files. This file format is a widely adopted industry standard when it comes to archiving and compressing digital data. You can use it to package together several related files.
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.
Zip and gzip are two completely different file formats. Take a look at java.util.zip.GZIPOutputStream
and java.util.zip.GZIPInputStream
:
InputStream in = new BufferedInputStream(
new GZIPInputStream( new FileInputStream( file) )
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With