wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes zip file bug? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "zip file bug?" Watch "zip file bug?" New topic
Author

zip file bug?

vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
Hello, I used java.util.zip to create zip files. What I noticed is that if I try to open the zip file by double click on it, there's nothing inside.
Also if I try to extract it manually (right click and choose extract), it will encounter error.

Has anyone encounter this before? This is so weird because the code I used is the common ones you can find on the internet.


I'm not available, my BF's name is WORK.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

There's a bug if what you describe is happening. But it's almost certainly a bug in your code. Would you like to post a short self-contained example?
vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
Hi Paul here's the code:

vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
Hi does anyone have the same problem here? Does your zip file has any files in it after you create them using java.util.zip?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Yes, I've created zip files successfully using the package.

Place some print statements inside that code to make sure that the file is being read.
vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
Dear Keith,

Can you please check whether anything's wrong with my code? Please? I just want some verification on that.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Looks more or less okay to me. Of course if you pass it the name of a file that doesn't exist, it will throw an exception and you will have an empty zip file exactly as you describe. So better error-handling would be a good idea. Such as closing the ZipOutputStream in a finally block. At least then you would have an empty zip file that doesn't have errors.
vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
Hi Paul,

I didn't get any exceptions. The zip file generated even has a size bigger than 0kb but there's nothing inside. Weird?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I tried your code on a sample file, and it created the zip successfully, and I tested that I could extract.

So that would seem to suggest a problem in the file name that you're using. Double check and make sure that when you call the file, you are sending the correct file name with the correct path.
vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
Yeah guys, I finally solved it. The code won't work properly because the file name I passed into new ZipEntry() is a whole file path instead of name only. This actually caused it to reference the file path instead of creating it inside the zip file. Which is why my zip file still have a size but has no contents inside.

Anyway thanks a bunch for your help guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: zip file bug?
 
Similar Threads
JQ+ Installation nightmare..Please help!
extract .rar file with java
Java, oracle on NT
JDBC and JApplet
TOMCAT setup on HP