Source:
Http://blog.knowsky.com/251817.htm
Code:
Import Java.io.InputStream;
Import java.util.Enumeration;
Import Java.util.zip.ZipEntry;
Import Java.util.zip.ZipFile;
public class Readzipfile {
/**
* Traversing the contents of the zip
*
* @param zippathname
* @throws Exception
*/
public static void Listjarfile (String zippathname) throws exception{
ZipFile zipfile = new ZipFile (zippathname);
enumeration<? Extends zipentry> Zipentrys = Zipfile.entries ();
while (Zipentrys.hasmoreelements ()) {
ZipEntry zipentry = Zipentrys.nextelement ();
System.out.println (Zipentry.getname ());
}
}
/**
* Read an entry in the ZIP package
*
* @param zippathname
* @throws Exception
*/
public static void Getjarfilecontent (String zippathname) throws exception{
ZipFile zipfile = new ZipFile (zippathname);
ZipEntry zipentry = Zipfile.getentry ("Meta-inf/manifest.") MF ");
InputStream in = Zipfile.getinputstream (ZipEntry);
int c =-1;
while ((C=in.read ())!=-1) {
System.out.print ((char) (C & 0XFF));
}
if (in!=null) {
In.close ();
In=null;
}
System.out.println ();
}
/**
* @param args
*/
public static void Main (string[] args) throws Exception {
String jarname = "C:\\nice.zip";
Listjarfile (Jarname);
Getjarfilecontent (Jarname);
}
}