Java decompress the file
Import org.apache.tools.zip. ZipEntry;
Import org.apache.tools.zip. ZipFile;
Decompress the file
Configuration in maven
com.sun
tools
1.4.2
system
${java.home}/../lib/tools.jar
Public class UnzipUtil {private static void createFile (String path) {File dir = new File (path); if (! Dir. exists () {dir. mkdir () ;}// get the file name private static String getFileName (String name) {return name. substring (0, name. lastIndexOf (.));} public static void unzip (String zipFilePath, String unzipFilePath) throws Exception {// create a File file File to be decompressed = new File (zipFilePath ); // create the zip file object ZipFile zipFile = new ZipFile (File); // create the zip File decompression directory file unzipFile = new file (unzipFilePath ++ getFileName (File. get Name (); // if (! UnzipFile. exists () unzipFile. mkdirs (); // obtain the Enumeration zipEnum = zipFile. getEntries (); // defines the input and output stream object InputStream input = null; OutputStream output = null; // defines the object ZipEntry entry = null; // reads the entry while (zipEnum. hasMoreElements () {// obtain the current entry = (ZipEntry) zipEnum. nextElement (); String entryName = new String (entry. getName (); // use/to separate the entry names String names [] = entryName. split (\/); int le Ngth = names. length; String path = unzipFile. getAbsolutePath (); for (int v = 0; v <length; v ++) {if (v <length-1) {// path + =/+ names [v] +/; createFile (path);} else {// The last if (entryName. endsWith (/) // is the directory, then create the folder createFile (unzipFile. getAbsolutePath () +/+ entryName); else {// indicates the file, which is output to the file input = zipFile. getInputStream (entry); output = new FileOutputStream (new File (unzipF Ile. getAbsolutePath () +/+ entryName); byte [] buffer = new byte [1024*8]; int readLen = 0; while (readLen = input. read (buffer, 0, 1024*8 ))! =-1) output. write (buffer, 0, readLen); // close the stream input. close (); // write the cache to the hard disk output. flush (); output. close ();}}}}}}