aspose file tools*
The moose likes Java in General and the fly likes Getting an input stream for the contents of a Zip file inside a Zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting an input stream for the contents of a Zip file inside a Zip file" Watch "Getting an input stream for the contents of a Zip file inside a Zip file" New topic
Author

Getting an input stream for the contents of a Zip file inside a Zip file

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Hi;

I need to step through a Zip file and get an input stream for each file archived.

No problem. But if one of the files in there is also a Zip file I need to step through it and get inputstreams for all its content.

My problem is this second Zip file doesn't have a path on the system so I can't create a ZipFile for it. Is what I am trying to do even possible?

See code below.

Thanks,

Luke

package index;
import java.io.File;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.*;

public class ZipDocument {

public static void main(String[] args) {
try {
ZipFile zip = new ZipFile(new File("D:\\content\\randomDocuments\\randomDocuments.zip"));
ZipEntry zipEntry;
Enumeration files = zip.entries();
while (files.hasMoreElements()) {
zipEntry = (ZipEntry)files.nextElement();
String name = zipEntry.getName();
System.out.println("The zipped file " + name + " the following Data" );
InputStream in = zip.getInputStream(zipEntry);
if (name.endsWith(".zip")) {
System.out.println("There is a zip in this zip! " + name); //now what??
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


Luke
SCJP
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Why not extract the file to a temporary location and then read it as a fresh normal single ZIP file?

And please use the CODE tags.
[ March 04, 2005: Message edited by: Kashif Riaz ]
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
This may be what I will have to do. I was hoping to avoid IO operations in this case.

Thanks,

Luke
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Use ZipInputStream instead of ZipFile.

ZipFile is evil, anyway -- it fails for large files, where "large" isn't very large, depending on your system.


[Jess in Action][AskingGoodQuestions]
benny rusli
Ranch Hand

Joined: Jan 15, 2005
Posts: 72
I just want to tell that Ernest Friedman-Hill is right, use ZipInputStream instead of ZipFile, I have tested for 3 days to unzip my 120 GB Data without problem.
 
 
subject: Getting an input stream for the contents of a Zip file inside a Zip file