in my application I have to read Zipfiles (plain textfiles, zipped with gzip). Reading/writing through GZIPInputStream and GZIPOutputStream works fine, but when I try to open the Zipfiles using java.util.zip.ZipFile, an exception is thrown:
java.util.zip.ZipException: error in opening zip file
I just invoked the constructor like that:
new ZipFile(new File("myFile.txt.gz"))
The Zipfile is valid, I can open it with WinZip. It isn't in use by another program either.
Welcome to the JavaRanch. Zip and Gzip are different and incompatible file formats, that's why there's two different classes to handle them. Winzip is smart enough to know the difference and handle it. It can also handle JAR files (which are Zip files plus a manifest file) which is very useful when trying to resolve ClassNotFound errors.
Originally posted by Joe Ess: Welcome to the JavaRanch. Zip and Gzip are different and incompatible file formats, that's why there's two different classes to handle them.
Hmm... I understand, thanks.
The reason for my question: I'm reading the .gz-File through a GZIPInputStream and I implemented a Progressbar to visualize the process. The problem is: to calculate the actual status of the progressbar, I need the uncompressed filesize. I googled a lot for a hint to solve the problem - yet unsuccessful.
If you can't determine the length of a task, you can use an indeterminate progress bar to indicate that something is taking place (see the Swing Tutorial page on Progress Bar). You could also just fudge the uncompressed length. Just multiple the compressed size by some factor (there's a table of different file types, compression algorithms and compression ration here if you want some good estimates).