if(entry.isDirectory()) {
EnumerationzipArchiveEntries=zipFile.getEntries();
while(zipArchiveEntries.hasMoreElements()) {
ZipArchiveEntrytmpEntry=zipArchiveEntries.nextElement();
if(tmpEntry.getName().startsWith(filepath)&&!tmpEntry.isDirectory()) {
StringfileName=tmpEntry.getName();
fileName=fileName.substring(filepath.length(), fileName.length());
writeToFile(tmpEntry, fileName, destPath);
}
}
}else{
//解压文件
StringsrcFileName=filepath.substring(filepath.lastIndexOf(File.separator), filepath.length());
writeToFile(entry, srcFileName, destPath);
}
privatevoidwriteToFile(ZipArchiveEntryentry,StringsrcFileName,StringdestPath)throwsIOException{
InputStreaminputStream=zipFile.getInputStream(entry);
OutputStreamoutputStream;
FiledestDir=newFile(destPath);
if(!destDir.exists()) {
destDir.mkdir();
}
if(destPath.endsWith(File.separator)) {
destPath+=srcFileName;
}else{
destPath=destPath+File.separator+srcFileName;
}
Filefile=newFile(destPath);
Filedir=file.getParentFile();
if(!dir.exists())
dir.mkdirs();
outputStream=newFileOutputStream(destPath);
byte[] buffer=newbyte[1024];
intsize;
while((size=inputStream.read(buffer))>0) {
outputStream.write(buffer,0, size);
}
outputStream.close();
inputStream.close();
}