*
The moose likes I/O and Streams and the fly likes error in opening zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "error in opening zip file" Watch "error in opening zip file" New topic
Author

error in opening zip file

Jens M Mayer
Greenhorn

Joined: Aug 27, 2007
Posts: 4
Hi,

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.

Any suggestions what the problem might be ?

I'm using jdk 1.5 with win xp.

Thanks in advance,

jens
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8834
    
    7

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jens M Mayer
Greenhorn

Joined: Aug 27, 2007
Posts: 4
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.

Does anybody have an idea ?

jens
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8834
    
    7

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).
 
Consider Paul's rocket mass heater.
 
subject: error in opening zip file
 
Similar Threads
compressing/uncompressing folders
zip file problem
Opening a zip file using the ZipFile class
Servlet sends zip file to client
What can be the problem cause ?