- 浏览: 101964 次
- 来自: ...
-
文章分类
最新评论
-
basnio123:
你好,同行想了解这个Liferay的开发应用,能否提供相关的开 ...
portal开源项目的选择-个人见解 -
yys2020:
谢谢了!哈哈 我顺利通过了... 但是有一道题改了
javaeye的论坛小测验——答案 -
wmj2003:
14.interests=newString[]{" ...
struts2的checkbox和checkboxlist两个标签的使用 -
emilyHong:
如果修改的时候
用checkboxList标签我应该怎么获取我 ...
struts2的checkbox和checkboxlist两个标签的使用 -
wmj2003:
抱歉刚看到。不会吧,我都测试过了,而且还在正式的项目中使用了。 ...
序列号生成器
本文使用了jdk1.5.0_13的源代码。(java.uti.zip*)
实现方法:首先将java.uti.zip中的源代码解压出来。找到DeflaterOutputStream、InflaterInputStream、ZipConstants、ZipEntry、ZipInputStream、ZipOutputStream,放到新的包com.work.util.zip中,重新组织这些文件的import,能使用当前包中类的就使用当前包中的类。
重点要修改的类:ZipEntry,修改内容如下:
- //修改对应的程序,在这里加载zip库
- static{
- /*loadtheziplibrary*/
- java.security.AccessController
- .doPrivileged(newsun.security.action.LoadLibraryAction("zip"));
- //initIDs();
- }
- //static{
- ///*ZiplibraryisloadedfromSystem.initializeSystemClass*/
- //initIDs();
- //}
- //privatestaticnativevoidinitIDs();
其次修改ZipInputStream,大约在279行。
- //ZipEntrye=createZipEntry(getUTF8String(b,0,len));
- ZipEntrye=null;
- try{
- if(this.encoding.toUpperCase().equals("UTF-8"))
- e=createZipEntry(getUTF8String(b,0,len));
- else
- e=createZipEntry(newString(b,0,len,this.encoding));
- }catch(ExceptionbyteE){
- e=createZipEntry(getUTF8String(b,0,len));
- }
- //增加构造方法
- private String encoding = "UTF-8";
- public ZipInputStream(InputStream in, String encoding) {
super(new PushbackInputStream(in, 512), new Inflater(true), 512);
usesDefaultInflater = true;
if (in == null) {
throw new NullPointerException("in is null");
}
this.encoding = encoding;
}
再次修改ZipOutputStream类,源代码如下:
- /*
- *@(#)ZipOutputStream.java1.3103/12/19
- *
- *Copyright2004SunMicrosystems,Inc.Allrightsreserved.
- *SUNPROPRIETARY/CONFIDENTIAL.Useissubjecttolicenseterms.
- */
- packagecom.work.util.zip;
- importjava.io.IOException;
- importjava.io.OutputStream;
- importjava.util.Enumeration;
- importjava.util.Hashtable;
- importjava.util.Vector;
- importjava.util.zip.CRC32;
- importjava.util.zip.Deflater;
- importjava.util.zip.ZipException;
- /**
- *ThisclassimplementsanoutputstreamfilterforwritingfilesintheZIP
- *fileformat.Includessupportforbothcompressedanduncompressedentries.
- *
- *@authorDavidConnelly
- *@version1.31,12/19/03
- */
- publicclassZipOutputStreamextendsDeflaterOutputStreamimplements
- ZipConstants{
- privateZipEntryentry;
- privateVectorentries=newVector();
- privateHashtablenames=newHashtable();
- privateCRC32crc=newCRC32();
- privatelongwritten=0;
- privatelonglocoff=0;
- privateStringcomment;
- privateintmethod=DEFLATED;
- privatebooleanfinished;
- privatebooleanclosed=false;
- /**
- *Checktomakesurethatthisstreamhasnotbeenclosed
- */
- privatevoidensureOpen()throwsIOException{
- if(closed){
- thrownewIOException("Streamclosed");
- }
- }
- /**
- *Compressionmethodforuncompressed(STORED)entries.
- */
- publicstaticfinalintSTORED=ZipEntry.STORED;
- /**
- *Compressionmethodforcompressed(DEFLATED)entries.
- */
- publicstaticfinalintDEFLATED=ZipEntry.DEFLATED;
- privateStringencoding="UTF-8";
- publicZipOutputStream(OutputStreamout,Stringencoding){
- super(out,newDeflater(Deflater.DEFAULT_COMPRESSION,true));
- usesDefaultDeflater=true;
- this.encoding=encoding;
- }
- /**
- *CreatesanewZIPoutputstream.
- *
- *@paramout
- *theactualoutputstream
- */
- publicZipOutputStream(OutputStreamout){
- super(out,newDeflater(Deflater.DEFAULT_COMPRESSION,true));
- usesDefaultDeflater=true;
- }
- /**
- *SetstheZIPfilecomment.
- *
- *@paramcomment
- *thecommentstring
- *@exceptionIllegalArgumentException
- *ifthelengthofthespecifiedZIPfilecommentisgreater
- *than0xFFFFbytes
- */
- publicvoidsetComment(Stringcomment){
- if(comment!=null&&comment.length()>0xffff/3
- &&getUTF8Length(comment)>0xffff){
- thrownewIllegalArgumentException("ZIPfilecommenttoolong.");
- }
- this.comment=comment;
- }
- /**
- *Setsthedefaultcompressionmethodforsubsequententries.Thisdefault
- *willbeusedwheneverthecompressionmethodisnotspecifiedforan
- *individualZIPfileentry,andisinitiallysettoDEFLATED.
- *
- *@parammethod
- *thedefaultcompressionmethod
- *@exceptionIllegalArgumentException
- *ifthespecifiedcompressionmethodisinvalid
- */
- publicvoidsetMethod(intmethod){
- if(method!=DEFLATED&&method!=STORED){
- thrownewIllegalArgumentException("invalidcompressionmethod");
- }
- this.method=method;
- }
- /**
- *SetsthecompressionlevelforsubsequententrieswhichareDEFLATED.The
- *defaultsettingisDEFAULT_COMPRESSION.
- *
- *@paramlevel
- *thecompressionlevel(0-9)
- *@exceptionIllegalArgumentException
- *ifthecompressionlevelisinvalid
- */
- publicvoidsetLevel(intlevel){
- def.setLevel(level);
- }
- /**
- *BeginswritinganewZIPfileentryandpositionsthestreamtothestart
- *oftheentrydata.Closesthecurrententryifstillactive.Thedefault
- *compressionmethodwillbeusedifnocompressionmethodwasspecified
- *fortheentry,andthecurrenttimewillbeusediftheentryhasnoset
- *modificationtime.
- *
- *@parame
- *theZIPentrytobewritten
- *@exceptionZipException
- *ifaZIPformaterrorhasoccurred
- *@exceptionIOException
- *ifanI/Oerrorhasoccurred
- */
- publicvoidputNextEntry(ZipEntrye)throwsIOException{
- ensureOpen();
- if(entry!=null){
- closeEntry();//closepreviousentry
- }
- if(e.time==-1){
- e.setTime(System.currentTimeMillis());
- }
- if(e.method==-1){
- e.method=method;//usedefaultmethod
- }
- switch(e.method){
- caseDEFLATED:
- if(e.size==-1||e.csize==-1||e.crc==-1){
- //storesize,compressedsize,andcrc-32indatadescriptor
- //immediatelyfollowingthecompressedentrydata
- e.flag=8;
- }elseif(e.size!=-1&&e.csize!=-1&&e.crc!=-1){
- //storesize,compressedsize,andcrc-32inLOCheader
- e.flag=0;
- }else{
- thrownewZipException(
- "DEFLATEDentrymissingsize,compressedsize,orcrc-32");
- }
- e.version=20;
- break;
- caseSTORED:
- //compressedsize,uncompressedsize,andcrc-32mustallbe
- //setforentriesusingSTOREDcompressionmethod
- if(e.size==-1){
- e.size=e.csize;
- }elseif(e.csize==-1){
- e.csize=e.size;
- }elseif(e.size!=e.csize){
- thrownewZipException(
- "STOREDentrywherecompressed!=uncompressedsize");
- }
- if(e.size==-1||e.crc==-1){
- thrownewZipException(
- "STOREDentrymissingsize,compressedsize,orcrc-32");
- }
- e.version=10;
- e.flag=0;
- break;
- default:
- thrownewZipException("unsupportedcompressionmethod");
- }
- e.offset=written;
- if(names.put(e.name,e)!=null){
- thrownewZipException("duplicateentry:"+e.name);
- }
- writeLOC(e);
- entries.addElement(e);
- entry=e;
- }
- /**
- *ClosesthecurrentZIPentryandpositionsthestreamforwritingthe
- *nextentry.
- *
- *@exceptionZipException
- *ifaZIPformaterrorhasoccurred
- *@exceptionIOException
- *ifanI/Oerrorhasoccurred
- */
- publicvoidcloseEntry()throwsIOException{
- ensureOpen();
- ZipEntrye=entry;
- if(e!=null){
- switch(e.method){
- caseDEFLATED:
- def.finish();
- while(!def.finished()){
- deflate();
- }
- if((e.flag&8)==0){
- //verifysize,compressedsize,andcrc-32settings
- if(e.size!=def.getBytesRead()){
- thrownewZipException("invalidentrysize(expected"
- +e.size+"butgot"+def.getBytesRead()
- +"bytes)");
- }
- if(e.csize!=def.getBytesWritten()){
- thrownewZipException(
- "invalidentrycompressedsize(expected"
- +e.csize+"butgot"
- +def.getBytesWritten()+"bytes)");
- }
- if(e.crc!=crc.getValue()){
- thrownewZipException(
- "invalidentryCRC-32(expected0x"
- +Long.toHexString(e.crc)
- +"butgot0x"
- +Long.toHexString(crc.getValue())
- +")");
- }
- }else{
- e.size=def.getBytesRead();
- e.csize=def.getBytesWritten();
- e.crc=crc.getValue();
- writeEXT(e);
- }
- def.reset();
- written+=e.csize;
- break;
- caseSTORED:
- //wealreadyknowthatbothe.sizeande.csizearethesame
- if(e.size!=written-locoff){
- thrownewZipException("invalidentrysize(expected"
- +e.size+"butgot"+(written-locoff)
- +"bytes)");
- }
- if(e.crc!=crc.getValue()){
- thrownewZipException("invalidentrycrc-32(expected0x"
- +Long.toHexString(e.crc)+"butgot0x"
- +Long.toHexString(crc.getValue())+")");
- }
- break;
- default:
- thrownewInternalError("invalidcompressionmethod");
- }
- crc.reset();
- entry=null;
- }
- }
- /**
- *WritesanarrayofbytestothecurrentZIPentrydata.Thismethodwill
- *blockuntilallthebytesarewritten.
- *
- *@paramb
- *thedatatobewritten
- *@paramoff
- *thestartoffsetinthedata
- *@paramlen
- *thenumberofbytesthatarewritten
- *@exceptionZipException
- *ifaZIPfileerrorhasoccurred
- *@exceptionIOException
- *ifanI/Oerrorhasoccurred
- */
- publicsynchronizedvoidwrite(byte[]b,intoff,intlen)
- throwsIOException{
- ensureOpen();
- if(off<0||len<0||off>b.length-len){
- thrownewIndexOutOfBoundsException();
- }elseif(len==0){
- return;
- }
- if(entry==null){
- thrownewZipException("nocurrentZIPentry");
- }
- switch(entry.method){
- caseDEFLATED:
- super.write(b,off,len);
- break;
- caseSTORED:
- written+=len;
- if(written-locoff>entry.size){
- thrownewZipException(
- "attempttowritepastendofSTOREDentry");
- }
- out.write(b,off,len);
- break;
- default:
- thrownewInternalError("invalidcompressionmethod");
- }
- crc.update(b,off,len);
- }
- /**
- *FinisheswritingthecontentsoftheZIPoutputstreamwithoutclosing
- *theunderlyingstream.Usethismethodwhenapplyingmultiplefiltersin
- *successiontothesameoutputstream.
- *
- *@exceptionZipException
- *ifaZIPfileerrorhasoccurred
- *@exceptionIOException
- *ifanI/Oexceptionhasoccurred
- */
- publicvoidfinish()throwsIOException{
- ensureOpen();
- if(finished){
- return;
- }
- if(entry!=null){
- closeEntry();
- }
- if(entries.size()<1){
- thrownewZipException("ZIPfilemusthaveatleastoneentry");
- }
- //writecentraldirectory
- longoff=written;
- Enumeratione=entries.elements();
- while(e.hasMoreElements()){
- writeCEN((ZipEntry)e.nextElement());
- }
- writeEND(off,written-off);
- finished=true;
- }
- /**
- *ClosestheZIPoutputstreamaswellasthestreambeingfiltered.
- *
- *@exceptionZipException
- *ifaZIPfileerrorhasoccurred
- *@exceptionIOException
- *ifanI/Oerrorhasoccurred
- */
- publicvoidclose()throwsIOException{
- if(!closed){
- super.close();
- closed=true;
- }
- }
- /*
- *Writeslocalfile(LOC)headerforspecifiedentry.
- */
- privatevoidwriteLOC(ZipEntrye)throwsIOException{
- writeInt(LOCSIG);//LOCheadersignature
- writeShort(e.version);//versionneededtoextract
- writeShort(e.flag);//generalpurposebitflag
- writeShort(e.method);//compressionmethod
- writeInt(e.time);//lastmodificationtime
- if((e.flag&8)==8){
- //storesize,uncompressedsize,andcrc-32indatadescriptor
- //immediatelyfollowingcompressedentrydata
- writeInt(0);
- writeInt(0);
- writeInt(0);
- }else{
- writeInt(e.crc);//crc-32
- writeInt(e.csize);//compressedsize
- writeInt(e.size);//uncompressedsize
- }
- //byte[]nameBytes=getUTF8Bytes(e.name);
- byte[]nameBytes=null;
- try{
- if(this.encoding.toUpperCase().equals("UTF-8"))
- nameBytes=getUTF8Bytes(e.name);
- else
- nameBytes=e.name.getBytes(this.encoding);
- }catch(ExceptionbyteE){
- nameBytes=getUTF8Bytes(e.name);
- }
- writeShort(nameBytes.length);
- writeShort(e.extra!=null?e.extra.length:0);
- writeBytes(nameBytes,0,nameBytes.length);
- if(e.extra!=null){
- writeBytes(e.extra,0,e.extra.length);
- }
- locoff=written;
- }
- /*
- *Writesextradatadescriptor(EXT)forspecifiedentry.
- */
- privatevoidwriteEXT(ZipEntrye)throwsIOException{
- writeInt(EXTSIG);//EXTheadersignature
- writeInt(e.crc);//crc-32
- writeInt(e.csize);//compressedsize
- writeInt(e.size);//uncompressedsize
- }
- /*
- *Writecentraldirectory(CEN)headerforspecifiedentry.REMIND:add
- *supportforfileattributes
- */
- privatevoidwriteCEN(ZipEntrye)throwsIOException{
- writeInt(CENSIG);//CENheadersignature
- writeShort(e.version);//versionmadeby
- writeShort(e.version);//versionneededtoextract
- writeShort(e.flag);//generalpurposebitflag
- writeShort(e.method);//compressionmethod
- writeInt(e.time);//lastmodificationtime
- writeInt(e.crc);//crc-32
- writeInt(e.csize);//compressedsize
- writeInt(e.size);//uncompressedsize
- //byte[]nameBytes=getUTF8Bytes(e.name);
- byte[]nameBytes=null;
- try{
- if(this.encoding.toUpperCase().equals("UTF-8"))
- nameBytes=getUTF8Bytes(e.name);
- else
- nameBytes=e.name.getBytes(this.encoding);
- }catch(ExceptionbyteE){
- nameBytes=getUTF8Bytes(e.name);
- }
- writeShort(nameBytes.length);
- writeShort(e.extra!=null?e.extra.length:0);
- byte[]commentBytes;
- if(e.comment!=null){
- //commentBytes=getUTF8Bytes(e.comment);
- try{
- if(this.encoding.toUpperCase().equals("UTF-8"))
- commentBytes=getUTF8Bytes(e.comment);
- else
- commentBytes=e.comment.getBytes(this.encoding);
- }catch(ExceptionbyteE){
- commentBytes=getUTF8Bytes(e.comment);
- }
- writeShort(commentBytes.length);
- }else{
- commentBytes=null;
- writeShort(0);
- }
- writeShort(0);//startingdisknumber
- writeShort(0);//internalfileattributes(unused)
- writeInt(0);//externalfileattributes(unused)
- writeInt(e.offset);//relativeoffsetoflocalheader
- writeBytes(nameBytes,0,nameBytes.length);
- if(e.extra!=null){
- writeBytes(e.extra,0,e.extra.length);
- }
- if(commentBytes!=null){
- writeBytes(commentBytes,0,commentBytes.length);
- }
- }
- /*
- *Writesendofcentraldirectory(END)header.
- */
- privatevoidwriteEND(longoff,longlen)throwsIOException{
- writeInt(ENDSIG);//ENDrecordsignature
- writeShort(0);//numberofthisdisk
- writeShort(0);//centraldirectorystartdisk
- writeShort(entries.size());//numberofdirectoryentriesondisk
- writeShort(entries.size());//totalnumberofdirectoryentries
- writeInt(len);//lengthofcentraldirectory
- writeInt(off);//offsetofcentraldirectory
- if(comment!=null){//zipfilecomment
- //byte[]b=getUTF8Bytes(comment);
- byte[]b=null;
- try{
- if(this.encoding.toUpperCase().equals("UTF-8"))
- b=getUTF8Bytes(comment);
- else
- b=comment.getBytes(this.encoding);
- }catch(ExceptionbyteE){
- b=getUTF8Bytes(comment);
- }
- writeShort(b.length);
- writeBytes(b,0,b.length);
- }else{
- writeShort(0);
- }
- }
- /*
- *Writesa16-bitshorttotheoutputstreaminlittle-endianbyteorder.
- */
- privatevoidwriteShort(intv)throwsIOException{
- OutputStreamout=this.out;
- out.write((v>>>0)&0xff);
- out.write((v>>>8)&0xff);
- written+=2;
- }
- /*
- *Writesa32-bitinttotheoutputstreaminlittle-endianbyteorder.
- */
- privatevoidwriteInt(longv)throwsIOException{
- OutputStreamout=this.out;
- out.write((int)((v>>>0)&0xff));
- out.write((int)((v>>>8)&0xff));
- out.write((int)((v>>>16)&0xff));
- out.write((int)((v>>>24)&0xff));
- written+=4;
- }
- /*
- *Writesanarrayofbytestotheoutputstream.
- */
- privatevoidwriteBytes(byte[]b,intoff,intlen)throwsIOException{
- super.out.write(b,off,len);
- written+=len;
- }
- /*
- *ReturnsthelengthofString'sUTF8encoding.
- */
- staticintgetUTF8Length(Strings){
- intcount=0;
- for(inti=0;i<s.length();i++){
- charch=s.charAt(i);
- if(ch<=0x7f){
- count++;
- }elseif(ch<=0x7ff){
- count+=2;
- }else{
- count+=3;
- }
- }
- returncount;
- }
- /*
- *ReturnsanarrayofbytesrepresentingtheUTF8encodingofthespecified
- *String.
- */
- privatestaticbyte[]getUTF8Bytes(Strings){
- char[]c=s.toCharArray();
- intlen=c.length;
- //Countthenumberofencodedbytes...
- intcount=0;
- for(inti=0;i<len;i++){
- intch=c[i];
- if(ch<=0x7f){
- count++;
- }elseif(ch<=0x7ff){
- count+=2;
- }else{
- count+=3;
- }
- }
- //Nowreturntheencodedbytes...
- byte[]b=newbyte[count];
- intoff=0;
- for(inti=0;i<len;i++){
- intch=c[i];
- if(ch<=0x7f){
- b[off++]=(byte)ch;
- }elseif(ch<=0x7ff){
- b[off++]=(byte)((ch>>6)|0xc0);
- b[off++]=(byte)((ch&0x3f)|0x80);
- }else{
- b[off++]=(byte)((ch>>12)|0xe0);
- b[off++]=(byte)(((ch>>6)&0x3f)|0x80);
- b[off++]=(byte)((ch&0x3f)|0x80);
- }
- }
- returnb;
- }
- }
剩下的工作就是编写压缩和解压缩的功能类了ZipUtil.java
- packagecom.work.util;
- importjava.io.BufferedInputStream;
- importjava.io.BufferedOutputStream;
- importjava.io.File;
- importjava.io.FileInputStream;
- importjava.io.FileNotFoundException;
- importjava.io.FileOutputStream;
- importjava.io.IOException;
- importjava.io.InputStream;
- importorg.apache.commons.logging.Log;
- importorg.apache.commons.logging.LogFactory;
- importcom.work.util.zip.ZipInputStream;
- importcom.work.util.zip.ZipOutputStream;
- importcom.work.util.zip.ZipEntry;
- /**
- *@projectproxool-0.9.1中的java.util.zip包和此类联合使用
- *@authorwangmingjie
- *
- */
- publicclassZipUtil{
- privatestaticLoglog=LogFactory.getLog(ZipUtil.class);
- /**
- *解压缩文件夹。
- *
- *@paramsrcFilename
- *@paramdestFilename
- *@paramoverwrite
- *@throwsIOException
- */
- publicvoidunzipDir(StringsrcFilename,booleanoverwrite)throwsIOException{
- FilesrcFile=newFile(srcFilename);
- //首先判断源文件是否存在
- if(!srcFile.exists()){
- thrownewFileNotFoundException("Cannotfindthesourcefile:"
- +srcFile.getAbsolutePath());
- }
- //判断源文件是否可读
- if(!srcFile.canRead()){
- thrownewIOException("Cannotreadthesourcefile:"
- +srcFile.getAbsolutePath());
- }
- FileInputStreamfin=null;
- BufferedInputStreaminputStream=null;
- ZipInputStreamzipInputStream=null;
- try{
- fin=newFileInputStream(srcFile);
- inputStream=newBufferedInputStream(fin);
- zipInputStream=newZipInputStream(inputStream,"gbk");//在这里设置编码格式,解决文件名和备注乱码问题
- ZipEntryzipEntry=null;
- StringtempFileName=null;
- while((zipEntry=zipInputStream.getNextEntry())!=null){
- tempFileName=zipEntry.getName();
- if(zipEntry.isDirectory()){
- //创建文件夹
- FileUtil.createDirs(tempFileName,true);
- }else{
- tempFileName=tempFileName.replace("\\","/");
- //System.out.println("文件夹="+tempFileName.substring(0,tempFileName.lastIndexOf("/")));
- FileUtil.createDirs(tempFileName.substring(0,tempFileName.lastIndexOf("/")),true);
- //System.out.println("tempFileName="+tempFileName);
- unzipFile(zipInputStream,tempFileName);//解压缩
- }
- zipInputStream.closeEntry();//关闭当前ZIP条目并定位流以读取下一个条目。
- //不写上面的一句,程序也能够正常运行。
- }
- }finally{
- if(zipInputStream!=null){
- try{
- zipInputStream.close();
- }catch(IOExceptionex){
- //justignore
- }
- }
- if(inputStream!=null){
- try{
- inputStream.close();
- }catch(IOExceptionex){
-
</span
发表评论
相关推荐
在Java编程语言中,我们...总的来说,Java中的ZIP压缩和解压缩功能强大且易于使用,是开发人员处理文件压缩需求的首选工具。通过熟练掌握`java.util.zip`包,你可以轻松地在Java应用程序中实现文件的压缩和解压缩功能。
本篇文章将深入探讨如何使用Ant实现ZIP文件的压缩和解压缩。 首先,Ant是基于XML的,因此我们需要在项目中创建一个名为`build.xml`的配置文件,这个文件包含了所有构建任务的定义。对于ZIP压缩,我们可以使用`<zip>...
本文将详细介绍如何使用 Java 实现 ZIP 文件的压缩和解压缩功能,并通过具体的代码示例来展示其实现过程。 #### Java 中 ZIP 文件处理的核心类 Java 提供了两个核心类来处理 ZIP 文件:`ZipOutputStream` 和 `...
Java标准库的java.util.zip包通常适用于简单的ZIP格式压缩与解压缩,Apache Commons Compress和Java Zip4j提供了更多的压缩格式和功能选项。对于大型数据集和高性能要求的场景,还可以考虑使用专门的压缩工具或算法...
本篇文章将详细探讨如何使用Java内置的类库来实现ZIP文件的压缩和解压缩,以及解决中文文件名出现乱码的问题。 首先,我们要了解Java中处理ZIP文件的核心类:`java.util.zip.ZipOutputStream` 和 `java.util.zip....
这里我们将深入探讨如何使用Java实现这一功能,主要关注ZIP文件格式的压缩和解压缩。 首先,Java标准库提供了一个名为`java.util.zip`的包,它包含了处理压缩文件所需的类。其中,`ZipOutputStream`用于创建ZIP文件...
以下是一份详细的介绍,讲解如何利用Java来实现ZIP文件的压缩和解压缩功能。 首先,我们要理解ZIP文件格式。ZIP是一种广泛使用的文件归档格式,它能将多个文件或目录打包成一个单一的ZIP文件,方便存储和传输。在...
在Java编程环境中,处理文件压缩和解压缩是常见的任务,特别是在构建可执行的JAR包或者处理数据传输时。本文将深入探讨如何使用Java来处理ZIP文件,特别是针对标题所提及的“java 中 zip压缩文件解压工具类”。我们...
在Java编程环境中,处理压缩和解压缩文件是常见的任务,主要涉及到两个标准库中的类:`java.util.zip`和第三方库如Apache Commons Compress。本文将深入探讨如何使用Java实现ZIP和RAR类型的压缩与解压操作,以及相关...
Java编程语言提供了强大的文件压缩和解压缩功能,主要通过java.util.zip包中的类来实现,如ZipOutputStream用于压缩,ZipInputStream用于解压缩。本篇将深入探讨这些关键类的使用方法,以及在Java中处理ZIP文件的...
本文将深入探讨如何使用Java API来处理ZIP文件格式的压缩和解压缩操作。 首先,我们要了解Java标准库中的`java.util.zip`包,这个包提供了对ZIP文件格式的支持。主要涉及的类有`ZipEntry`和`ZipOutputStream`用于...
Java中的zip文件压缩和解压缩是程序开发中常见的任务,特别是在处理大量数据或者打包资源文件时。Apache Commons Compress库是Java中一个强大的工具,它提供了对多种压缩格式的支持,包括zip,而且能够处理中文...
5. **代码实现**:在`src`目录中,通常会包含Java源代码文件,如`ZipUtils.java`,其中包含了压缩和解压缩的静态方法。这些方法可能包括`compressFilesWithPassword()`和`unzipWithPassword()`,分别用于压缩和解...
在Java中,我们可以使用java.util.zip包中的ZipOutputStream和ZipInputStream类来对Zip文件进行压缩和解压缩操作。 **压缩Zip文件:** 要压缩一组文件到一个Zip文件,我们需要创建一个ZipOutputStream实例,然后...
在标题中提到的"java实现对文件或文件夹的压缩和解压缩",我们可以使用这个库来实现。具体来说,我们可以创建一个`ZipUtil`类,里面包含压缩和解压缩的静态方法。 首先,为了压缩文件或文件夹,我们需要使用`org....
在Java编程语言中,压缩和解压缩文件是常见的任务,特别是在处理大量数据或者进行文件传输时。本篇文章将深入探讨如何使用Java的内置库`java.util.zip`来实现Zip文件的压缩功能,尤其是针对多个文件的压缩实例。我们...
总结,Java的Zip压缩和解压缩功能通过`java.util.zip`包提供,开发者可以根据具体需求灵活运用,创建自定义的压缩和解压缩工具。无论是单个文件还是整个目录,都能轻松实现。在实际开发中,这些工具可以极大地提高...
JavaZip压缩类是Java编程语言中用于处理ZIP文件格式的核心工具,主要集中在java.util.zip包中。这个包提供了多种类和接口,使得开发者能够轻松地对数据进行压缩和解压缩,尤其是在开发需要处理大量数据的应用时,如...
本篇文章将深入探讨如何使用Java实现ZIP文件的压缩和解压缩操作,以及涉及的相关知识点。 首先,理解ZIP文件格式是基础。ZIP是一种通用的数据压缩和归档格式,可以包含多个文件和目录,每个都经过独立压缩。在Java...