• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

zip file bug?

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul here's the code:

 
vivien siu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic