This is how I did it. Once you finish downloading the zip fie from a url and you get a byte[] array out of it, simply pass it to a ByteArrayInputStream and pass that input stream to a ZipInputStream.

Check out the code:

In a zip file, every file or folder is represented by a ZipEntry. To browse through the zip file’s contents, loop the ZipInputStream and call getNextEntry() which returns a ZipEntry object.

To get the input stream of the file, just use the same ZipInputStream object. The developers did a slick job of designing this class.

Check out the code:

What the code does is that when getNextEntry() is called, it will go to the first file (or folder) in the list. The code assumes that there is only one file in the zip file and it reads the content of the file without having to save it.

You have to add code such as doing a check if the ZipEntry is a file or folder in case you have different file types in your zip file.

Related Posts Plugin for WordPress, Blogger...