读取zip压缩文件对文件夹部分的处理

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();

    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容