publicclassUrlTest {
publicstaticvoidmain(String[] args) {
try {
unzipFromLoc("D:\\LeanwoProgram_2018\\temp");
} catch (Exceptione) {
e.printStackTrace();
}
}
publicstaticvoidunzipFromLoc(StringfilePath) throwsException{
Filefile=newFile(filePath);
File[] list=file.listFiles();
Stringfrom="";
Stringto="D:\\LeanwoProgram_2018\\temp\\";
for(Filef : list){
booleanbool=f.isFile();
if(bool){
from=f.getAbsolutePath();
unZipFiles(newFile(from),to);
}
}
}
publicstaticvoidunZipFiles(FilezipFile, StringdescDir) throwsIOException {
ZipFilezip=newZipFile(zipFile,Charset.forName("GBK"));Stringname=zip.getName().substring(zip.getName().lastIndexOf('\\')+1, zip.getName().lastIndexOf('.'));
FilepathFile=newFile(descDir+name);
if (!pathFile.exists()) {
pathFile.mkdirs();
}
for (Enumeration<?extendsZipEntry>entries=zip.entries(); entries.hasMoreElements();) {
ZipEntryentry= (ZipEntry) entries.nextElement();
StringzipEntryName=entry.getName();
InputStreamin=zip.getInputStream(entry);
StringoutPath= (descDir+name+"/"+zipEntryName).replaceAll("\\*", "/");
Filefile=newFile(outPath.substring(0, outPath.lastIndexOf('/')));
if (!file.exists()) {
file.mkdirs();
}
if (newFile(outPath).isDirectory()) {
continue;
}
FileOutputStreamout=newFileOutputStream(outPath);
byte[] buf1=newbyte[1024];
intlen;
while ((len=in.read(buf1)) >0) {
out.write(buf1, 0, len);
}
in.close();
out.close();
}
System.out.println("******************解压完毕********************");
return;
}