Copy Code code as follows:
Import Java.io.File;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.OutputStream;
Import java.util.Enumeration;
Import Java.util.zip.ZipEntry;
Import Java.util.zip.ZipFile;
public class Unzipper {
/**
* Extract files to the current directory function equivalent to the right key to select decompression
* @param zipfile
* @param
* @author Gabriel
*/
@SuppressWarnings ("Rawtypes")
public static void Unzipfiles (File zipfile) throws ioexception{
Get the directory where the compressed files are located
String Path=zipfile.getabsolutepath ();
Path=path.substring (0,path.lastindexof ("\"));
SYSTEM.OUT.PRINTLN ("path" +path);
ZipFile zip = new ZipFile (ZipFile);
For (enumeration entries =zip.entries ();
Entries.hasmoreelements ();) {
ZipEntry entry = (zipentry) entries.nextelement ();
String zipentryname = Entry.getname ();
InputStream in = Zip.getinputstream (entry);
Outpath Output Directory
String Outpath = (path+ "\" +zipentryname). ReplaceAll ("\\*", "/")
System.out.println ("Outpath" +outpath);
To determine whether a path exists or not, create a file path
File File = new file (outpath.substring 0, Outpath.lastindexof ('/'));
if (!file.exists ()) {
File.mkdirs ();
}
To determine whether a file full path is a folder, if the above has been uploaded, do not need to decompress
if (new File (Outpath). Isdirectory ()) {
Continue
}
Output file path information
System.out.println (Outpath);
OutputStream out = new FileOutputStream (Outpath);
byte[] buf1 = new byte[1024];
int Len;
while ((Len=in.read (BUF1)) >0) {
Out.write (Buf1,0,len);
}
In.close ();
Out.close ();
}
System.out.println ("****************** decompression Complete ********************");
}
public static void Main (string[] args) {
try {
Unzipfiles (New File ("D:\\all\\zip\\default.adiumemoticonset.zip"));
catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}