This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

zip file bug?

 
vivien siu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul here's the code:

 
vivien siu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Keith,

Can you please check whether anything's wrong with my code? Please? I just want some verification on that.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic