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)
[下载]12230048341.rar
|