欢迎来到天天文库
浏览记录
ID:5782075
大小:31.50 KB
页数:11页
时间:2017-12-24
《压缩解压缩文件和目录的完整程序》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、压缩解压缩文件和目录的完整程序//一个压缩解压缩文件和目录的完整程序....//版权没有,随便使用.packagecross.pauliuyou.tool.io;importjava.io.*;importjava.util.*;importjava.util.zip.*;publicclassZipUtil{publicstaticintbufsize=8192;privateStringzipBase;privateintmaxFileNameLength;privatelongtotalLength;privatelongbytesHan
2、dled;privateStringgetSpace(intnum){Stringspace="";for(inti=0;imaxFileNameLength){maxFileNameLength=path.getPath().length();}}else{File[]fs
3、=path.listFiles();for(inti=0;i4、1024*1024*1024)){newValue=fileLength/(1024*1024);size=newValue+"MB";}else{newValue=fileLength/(1024*1024*1024);size=newValue+"GB";}returnsize;}publicvoidzip(Stringpath)throwsException{zip(path,null);}publicvoidzip(Stringpath,Stringdest)throwsException{Filef=newFile(path);if(5、!f.exists()){System.out.println("File:"+path+"NotExists!");return;}getLength(f);System.out.println("total"+lengthString(totalLength)+"tozip");Stringpath2="";for(inti=0;i6、th.lastIndexOf("/")==-1?0:path.lastIndexOf("/")+1);if(dest==null){if(f.isFile()){if(dest==null){zipBase="./";dest=path.substring(0,(path.lastIndexOf(".")==-1?path.length():path.lastIndexOf(".")))+".zip";}}else{path2=path.substring(0,path.lastIndexOf("/")==-1?path.length():pa7、th.lastIndexOf("/"));if(path.equals(path2)){dest=".";}dest=path2+"/"+zipBase.substring(0,(zipBase.lastIndexOf(".")==-1?zipBase.length():zipBase.lastIndexOf(".")))+".zip";}}ZipOutputStreamzipOut=newZipOutputStream(newFileOutputStream(dest));zipFile(f,zipOut);zipOut.close();Sy8、stem.out.print("r100%t");System.out.println(path+"hasbeencompressedtozipf
4、1024*1024*1024)){newValue=fileLength/(1024*1024);size=newValue+"MB";}else{newValue=fileLength/(1024*1024*1024);size=newValue+"GB";}returnsize;}publicvoidzip(Stringpath)throwsException{zip(path,null);}publicvoidzip(Stringpath,Stringdest)throwsException{Filef=newFile(path);if(
5、!f.exists()){System.out.println("File:"+path+"NotExists!");return;}getLength(f);System.out.println("total"+lengthString(totalLength)+"tozip");Stringpath2="";for(inti=0;i6、th.lastIndexOf("/")==-1?0:path.lastIndexOf("/")+1);if(dest==null){if(f.isFile()){if(dest==null){zipBase="./";dest=path.substring(0,(path.lastIndexOf(".")==-1?path.length():path.lastIndexOf(".")))+".zip";}}else{path2=path.substring(0,path.lastIndexOf("/")==-1?path.length():pa7、th.lastIndexOf("/"));if(path.equals(path2)){dest=".";}dest=path2+"/"+zipBase.substring(0,(zipBase.lastIndexOf(".")==-1?zipBase.length():zipBase.lastIndexOf(".")))+".zip";}}ZipOutputStreamzipOut=newZipOutputStream(newFileOutputStream(dest));zipFile(f,zipOut);zipOut.close();Sy8、stem.out.print("r100%t");System.out.println(path+"hasbeencompressedtozipf
6、th.lastIndexOf("/")==-1?0:path.lastIndexOf("/")+1);if(dest==null){if(f.isFile()){if(dest==null){zipBase="./";dest=path.substring(0,(path.lastIndexOf(".")==-1?path.length():path.lastIndexOf(".")))+".zip";}}else{path2=path.substring(0,path.lastIndexOf("/")==-1?path.length():pa
7、th.lastIndexOf("/"));if(path.equals(path2)){dest=".";}dest=path2+"/"+zipBase.substring(0,(zipBase.lastIndexOf(".")==-1?zipBase.length():zipBase.lastIndexOf(".")))+".zip";}}ZipOutputStreamzipOut=newZipOutputStream(newFileOutputStream(dest));zipFile(f,zipOut);zipOut.close();Sy
8、stem.out.print("r100%t");System.out.println(path+"hasbeencompressedtozipf
此文档下载收益归作者所有