52ky 发表于 2022-10-9 12:22:59

java8文件压缩解压技术

java8、lambda、stream使用publicclassZip_uncompressimplementsUncompressInterface{publicvoiduncompress(StringcompressFile,StringoutDir){try{ZipFilezf=newZipFile(compressFile);Enumerationlt;ZipEntrygt;enu=zf.getEntries();Listlt;ZipEntrygt;list=newArrayList();while(enu.hasMoreElements()){list.add(enu.nextElement());}list.forEach(p-gt;{try{java.nio.file.FileSystemfs=FileSystems.getDefault();intss=p.getName().lastIndexOf(\/\)+1;Stringpp=p.getName().substring(ss);nbsp<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>athpath=Paths.get(outDir+pp);System.out.println(\ZipFile:\+ss+path);if(!p.isDirectory()){if(!Files.exists(path.getParent()))Files.createDirectories(path.getParent());Files.copy(zf.getInputStream(p),path,StandardCopyOption.REPLACE_EXISTING);}}catch(Exceptione){catch{e.printStackTrace();}});}catch(IOExceptione){//TODO自动生成的catch块e.printStackTrace();}}

(Java8, lambda and stream use publicclassZip_ uncompressimplementsUncompressInterface{publicvoiduncompress(StringcompressFile,StringoutDir){try{ZipFilezf=newZipFile(compressFile);Enumerationlt;ZipEntrygt;enu=zf.getEntries();Listlt;ZipEntrygt;list=newArrayList();while(enu.hasMoreElements()){list.add(enu.nextElement());} list.forEach(p-gt;{try{java.nio.file.FileSystemfs=FileSystems.getDefault();intss=p.getName().lastIndexOf(\/\) 1;Stringpp=p.getName().substring(ss);nbsp<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>athpath=Paths.get(outDir pp);System.out.println(\ZipFile:\ ss path);if(!p.isDirectory()){if(!Files.exists(path.getParent()))Files.createDirectories(path.getParent());Files.copy(zf.getInputStream(p) ,path,StandardCopyOption.REPLACE_ EXISTING);}} catch(Exceptione){catch{e.printStackTrace();}});} Catch (IOExceptione) {//catch block e.printStackTrace();}} automatically generated by TODO)




页: [1]
查看完整版本: java8文件压缩解压技术