This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes How to unzip a zip file which contains another zip file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to unzip a zip file which contains another zip file?" Watch "How to unzip a zip file which contains another zip file?" New topic
Author

How to unzip a zip file which contains another zip file?

Ong CherYee
Greenhorn

Joined: Jan 17, 2008
Posts: 11
I would like to unzip a zip file which contains 2 text files and another zip file inside it.

For example, the zip file to unzip is called "Books.zip" and it contains 2 text files and another zip file called "Price.zip".

I googled for the unzipping code commonly found on the net and used it. But the problem is that the code can only unzip the 2 text files. It seems unable to retrieve the contents inside the "Price.zip" folder.

The code used is shown below:


How do I unzip and retrieve all the contents of a zip file which contains another zip file?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
For unzipping it doesn't matter what type the files are; they're just treated as bytes anyway. The process doesn't work recursively, though. After you've unzipped Books.zip, you'll need to re-run this code with Price.zip.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18


That should allow you to unzip the second file without extracting it. I'm a bit lazy regarding the copying here, but basically reading from a ZipInputStream reads everything for the current entry. You need to close that entry and go the next entry and copy everything again, until your done.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Don't get me started about those stupid light bulbs.
 
subject: How to unzip a zip file which contains another zip file?