public class UnZipper {
/**
* The function of decompressing files to the current directory is equivalent to right-clicking and selecting decompression.
* @param zipFile
* @param
* @author gabriel
*/
@SuppressWarnings("rawtypes")
public static void unZipFiles(File zipFile)throws IOException{
//Get the directory where the compressed file is 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);
//Determine whether the path exists, if not, create the file path
File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
if(!file.exists()){
file.mkdirs();
}
//Determine whether the full path of the file is a folder. If it has been uploaded above, there is no need to decompress it.
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 completed************************");
}
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();
}
}
}