File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error in opening zip file

 
Jens M Mayer
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jens M Mayer
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic