java 如何高速解压缩 |
您所在的位置:网站首页 › java解压缩 › java 如何高速解压缩 |
1./** *递归压缩文件夹 *@paramsrcRootDir压缩文件夹根目录的子路径 *@paramfile当前递归压缩的文件或目录对象 *@paramzos压缩文件存储对象 *@throwsException */ privatestaticvoidzip(StringsrcRootDir,Filefile,ZipOutputStreamzos)throwsException { if(file==null) { return; } 2.//如果是文件,则直接压缩该文件 if(file.isFile()) { intcount,bufferLen=1024; bytedata[]=newbyte[bufferLen]; //获取文件相对于压缩文件夹根目录的子路径 StringsubPath=file.getAbsolutePath(); intindex=subPath.indexOf(srcRootDir); if(index!=-1) { 3.subPath=subPath.substring(srcRootDir.length()+File.separator.length()); } ZipEntryentry=newZipEntry(subPath); zos.putNextEntry(entry); BufferedInputStreambis=newBufferedInputStream(newFileInputStream(file)); while((count=bis.read(data,0,bufferLen))!=-1) { zos.write(data,0,count); } bis.close(); zos.closeEntry(); } //如果是目录,则压缩整个目录 else { 4.//压缩目录中的文件或子目录 File[]childFileList=file.listFiles(); for(intn=0;n |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |