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.
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.
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.
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.