Does any one know how to write zip files into antoher zip file? In my application I have to provide the user to export the files he is intrested into a zip file. There are different category of files, so I need to put each category into a directory, zip it and put all the directories into another zip file.
assuming I have three directories which includes two files each,
directory1 directory2 directory3
Now I have to create three zip files for each of them director1.zip, directory2.zip, direcoty3.zip.
Then I have to create a zip file which contains all three zip files. Lets say "parentdirectory.zip".
How can I do this? I have tried it, but I could write indvidual files into the final directory "parentdirectory,zip". How can I write each "directory.zip" as it is into "parentdirectory,zip". So that my zip file contains the following structure
One more thing each time I create a individual zip for each directory it was leaving the directory in my file system. As I write this zip into the parentdirectory.zip anyway, I dont want the individual directory to be in my file system.
How have you tried to write the zip files into a new zip? You should be able to write them in exactly the same way you wrote the intial files into the zip.
If you want to get rid of an empty directory (is this what you meant?) create a File object for the directory and call it's delete() method. If the directory contains files you will need to delete them first - you can get a an array of all files using the directories File object's listFiles() method.
Now I'm confused, you said you wanted to add the zip files (as they are) to another zip file but the code you've shown appears to be attempting to unzip the zip file and add each individual entry to the new zip file.
Yes you are right, here I am extracting the files again and writing. This is my qeustion, how to read zip file? I tried reading the zip file just like a normal file it was throwing an expcetion saying that there is no zip entry.
Chinna K, your name is still not conforming to the JavaRanch naming policy. Your name should consist of a first name, space and a second name. A single letter "K" as a second name is not acceptable.
Please take a moment to carefully read the naming policy and change your display name.
You write a zip file into a zip file exactly the same way as you would write a pdf file into a zip file. That's all. Apparently you already know how to put files into a zip file, so just do that.
Thanks for your reply. I dont think that reading a zip file is not the same as reading any other file (say pdf or test). As per the tests I have run when you read a zip file you need to get the individual "ZipEntry" inside the zip file and write them. I dont know which way you are asking me to do that.
Thanks for your reply. I dont think that reading a zip file is not the same as reading any other file (say pdf or test). As per the tests I have run when you read a zip file you need to get the individual "ZipEntry" inside the zip file and write them. I dont know which way you are asking me to do that.
Correct me if I am wrong.
Thanks,
I think you are wrong. A file is just a series of bytes. If you were putting a pdf file into a zip file you would read its bytes and put them into a ZipEntry. Likewise if you are putting a zip file into a zip file you should read its bytes and put them into a ZipEntry. There's no difference at all. Don't try and make simple things complicated.
Thanks for correcting me. Actually I have tried reading the zip file as a normal file but because of some other bug in my code it didnt work. So, I thought like I have to use "ZipInputStream" to read the zip files. I tried it this time and corrected the other bug. It worked. Thanks
Glad to hear that. I have just spent the last five hours debugging something that turned out to be not a problem at all, so I know how that can happen.
Replace the word "snake" with "danger noodle" in all tiny ads.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth