Code:
Package Com.wicresoft.jpo;
Import Java.io.BufferedInputStream;
Import Java.io.BufferedReader;
Import Java.io.FileInputStream;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
Import Java.util.zip.ZipEntry;
Import Java.util.zip.ZipFile;
Import Java.util.zip.ZipInputStream; public class Readziputil {/** * @param args */public static void main (string[] args) {//TODO auto-generated Me
Thod stub try {readzipfile ("D://test//test.zip");
catch (Exception e) {//TODO auto-generated catch block E.printstacktrace ();
The public static void Readzipfile (String file) throws Exception {ZipFile ZF = new ZipFile (file);
InputStream in = new Bufferedinputstream (new FileInputStream (file));
Zipinputstream Zin = new Zipinputstream (in);
ZipEntry ze; while (ze = zin.getnextentry ())!= null) {if (Ze.isdirectory ()) {//System.out.print ("directory-" + Ze.getname
() + ":"//+ ze.getsize () + "bytes");
System.out.println (); } else {
System.err.println ("file-" + ze.getname () + ":" + ze.getsize () + "bytes");
Long size = Ze.getsize ();
if (Size > 0) {bufferedreader br = new BufferedReader (New InputStreamReader (Zf.getinputstream (Ze));
String Line;
while (line = Br.readline ())!= null) {System.out.println (line);
} br.close ();
} System.out.println ();
} zin.closeentry ();
}
}
An error may occur when the above code traverses the file in the zip: Java java.util.zip.ZipException:invalid entry size. The reason for the mistake is not clear.
Workaround: Change the way the file is traversed in the zip.
ZipFile ZF = new ZipFile (apkpath);
enumeration<? Extends zipentry> zes = Zf.entries ();
while (Zes.hasmoreelements ()) {
ZipEntry ze1 = Zes.nextelement ();
Perform other Actions
}