Summary
As a result of business requirements, the file system will be a part of the file processing packaging operations, beginning I use the JAVA6 comes with the API processing, when the file name with in, the compressed file after packaging will produce Chinese garbled problem, after hearing that java7 solved this problem, because the industry lag I did not do such an attempt, Interested readers can study it for themselves. Here is a solution for me (Apache under the file Stream tool).
//Partial Package Introduction SampleImportJava.io.File;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;ImportJava.io.IOException;ImportJava.io.InputStream;ImportJava.io.OutputStream;ImportJava.util.ArrayList;ImportJava.util.Enumeration;ImportJava.util.List;ImportOrg.apache.log4j.Logger;ImportOrg.apache.tools.zip.ZipEntry;ImportOrg.apache.tools.zip.ZipFile;ImportOrg.apache.tools.zip.ZipOutputStream; Public classZiputil {Private Static FinalLogger Logger = Logger.getlogger (ziputil.class);/** * Function: Compress multiple files into a zip file * @param srcfile: Source file list * @param zipfile: Compressed file */ Public StaticBoolean zipfiles (file[] Srcfile,file zipfile) {Boolean reflag =false;byte[] buf=New byte[10240]; Zipoutputstream out=NULL; FileInputStreaminch=NULL;Try{//zipoutputstream class: Complete compression of files or folders out=NewZipoutputstream (NewFileOutputStream (ZipFile));//Note Here the encoding settings out. setencoding ("GBK"); for(intI=0; i<srcfile.length;i++) {inch=NewFileInputStream (Srcfile[i]); out. Putnextentry (NewZipEntry (Srcfile[i].getname ()));intLen while((len=inch. Read (BUF)) >0){ out. Write (BUF,0, Len); } out. Closeentry ();inch. Close ();inch=NULL; } out. Close (); out=NULL; Reflag =true; Logger.info ("Compression complete, file details are:"+zipfile.getabsolutepath ()); }Catch(Exception e) {E.printstacktrace (); }finally{if(inch!=NULL){Try{inch. Close ();inch=NULL; }Catch(IOException e) {E.printstacktrace (); } }if( out!=NULL){Try{ out. Close (); out=NULL; }Catch(IOException e) {E.printstacktrace (); } } }returnReflag; } }
About using Java to bring Zipoutputstream compressed file name to Chinese garbled problem