Package com.common.util;
Import java.io.*;
Import java.util.ArrayList;
Import java.util.zip.*;
public class UnZip {
public static int icompresslevel; The range of compression ratio is 0~9
public static Boolean boverwrite; Whether to overwrite file with same name range is true and false
private static ArrayList Allfiles = new ArrayList ();
public static String Serrormessage;
public static ArrayList UnZip (String zippathfile, String destpath) {
ArrayList allfilename = new ArrayList ();
try {
Specify the location and filename of the compressed file, and create the FileInputStream object
FileInputStream in = new FileInputStream (zippathfile);
To pass fins into the Zipinputstream
Zipinputstream Zin = new Zipinputstream (in);
ZipEntry ent = null;
byte ch[] = new byte[256];
while ((ent = Zin.getnextentry ())!= null) {
File Zfile = new file (DestPath + ent.getname ());
File Fpath = new file (Zfile.getparentfile (). GetPath ());
if (Ent.isdirectory ()) {
if (!zfile.exists ())
Zfile.mkdirs ();
Zin.closeentry ();
} else {
if (!fpath.exists ())
Fpath.mkdirs ();
FileOutputStream Fouts = new FileOutputStream (zfile);
int i;
Allfilename.add (Zfile.getabsolutepath ());
while ((i = Zin.read (ch))!=-1)
Fouts.write (CH, 0, I);
Zin.closeentry ();
Fouts.close ();
}
System.out.println ("Extract file:" + ent.getname () + zippathfile);
}
In.close ();
Zin.close ();
Serrormessage = "OK";
catch (Exception e) {
SYSTEM.ERR.PRINTLN ("Extract error:" + e.getmessage ());
Serrormessage = E.getmessage ();
}
Allfiles.clear ();
System.out.println ("complete");
return allfilename;
}
public static void Main (string[] args) {
Unzip.unzip ("C://order_20.rar", "c://un//");
}
}