The example of this article describes the method of Java's method of creating ZIP compression files. Share it for everyone for your reference. The specifics are as follows:
Note here: It is recommended to use ORG.APACHE.Tools.zip.*Packing related classes, otherwise there may be a Chinese garbled problem.
/*** Compressed folder* @Param Sourcedir folder name (including path)* @param targetzipfile generates ZIP file name* @AutHor liuxiangwei*/Public Static Voidir (String Sourc Edir, String Targetzipfile) {Try {FileoutputStream Target = New FileOutPutStream (targetzipfile); zipoutputStream out = new zipoutPutstream (New BuffredoutStream (target)); int buffer_size = 1024; byte ] = new byte [buffer_size]; File Dir = New File (SourceDir); if (! Dir.isdirectory ( )) {Throw New iLlegalargumentexception (SourceDir+"is not a directory!"); FileInputStream Fi = New FileInputStream (FILES [i]); bufferedInputStream Origin = New BufferedInputStream (FI); Zipentry Entry = New Zipentry (Files [i] .getName ()); y); Int Count; While (Count = Origin.read (buff))! = -1) {out.write (buff, 0, count);} Origin.close ();} out.close ();} Catch (ioException E) {Throwing New Msgexception (""); }}It is hoped that this article is helpful to everyone's Java program design.