/** * @paramargs*/ Public Static voidMain (string[] args)throwsexception{zipoutputstream Zos=NULL; Zos=NewZipoutputstream (NewFileOutputStream ("C:\\temp7.zip")); String SS= "cname\t\tccode\t\tcreatedate\n"; SS+ = "DBC voucher 99\t\t111188\t\t2017-05-14\n"; SS+ = "Zc Voucher 99\t\t111199\t\t2017-05-14\n"; Createzip (Zos,"Temp7.txt", Ss.getbytes ()); String SS2= "cname\t\tccode\t\tcreatedate\n"; SS2+ = "DBC voucher 88\t\t111188\t\t2017-05-14\n"; SS2+ = "Zc Voucher 88\t\t111199\t\t2017-05-14\n"; Createzip (Zos,"Result7.txt", Ss2.getbytes ()); //Zos.flush (); //ExternalZos.closeentry (); Zos.close (); } Private Static voidCreatezip (Zipoutputstream zos,string fileName,byte[] b) {Try { // //Create ZipZos.putnextentry (NewZipEntry (fileName)); //Set the DeclearZos.setcomment ("by Zip test!"); Zos.write (b,0, B.length);//generate a ZIP file directly. Skip the TXT step}Catch(Exception e) {e.printstacktrace (); } }
Java directly generates ZIP compressed file Lite code (skip TXT file)