java ant包中的org.apache.tools.zip实现压缩和解压缩实例详解
javaant包中的org.apache.tools.zip实现压缩和解压缩实例详解
其实apache中的ant包(请自行GOOGLE之ant.jar)中有一个更好的类,已经支持中文了,我们就不重复制造轮子了,拿来用吧,
这里最主要的功能是实现了可以指定多个文件到同一个压缩包的功能
用org.apache.tools.zip压缩/解压缩zip文件的例子,用来解决中文乱码问题。
实例代码:
importJava.io.BufferedInputStream; importjava.io.BufferedOutputStream; importjava.io.File; importjava.io.FileInputStream; importjava.io.FileNotFoundException; importjava.io.FileOutputStream; importjava.io.IOException; importjava.io.InputStream; importjava.util.ArrayList; importjava.util.List; importjava.util.zip.CRC32; importjava.util.zip.CheckedOutputStream; importjava.util.zip.Deflater; importorg.apache.tools.zip.ZipEntry; importorg.apache.tools.zip.ZipOutputStream; /** *功能:使用ApacheAnt里提供的org.apache.tools.zip实现zip压缩和解压(支持中文文件名) *解决了由于java.util.zip包不支持汉字的问题。使用java.util.zip包时,当zip文件中有名字为中文的文件时, *就会出现异常:"Exceptioninthread"main"java.lang.IllegalArgumentExceptionat *java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:285) * *@author夏明龙E-mail:邮箱 *@version创建时间:2013-3-22上午10:40:21类说明: */ publicclassAntZipUtil{ privatestaticListlist=newArrayList(); privatestaticListlistFile(Stringpath){ Filefile=newFile(path); String[]array=null; StringsTemp=""; if(!file.isDirectory()){ returnnull; } array=file.list(); if(array.length>0){ for(inti=0;i感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!