java直接生成zip压缩文件精简代码(跳过txt文件)

/**
     * @param args
     */
    public static void main(String[] args) throws Exception{
        ZipOutputStream zos = null;
         zos = new ZipOutputStream(new FileOutputStream("c:\temp7.zip"));
         
         String ss = "cName		cCode		createDate
";
            ss += "dbc券99		111188		2017-05-14
";
            ss += "zc券99		111199		2017-05-14
";
            
         createZip(zos,"temp7.txt",ss.getBytes());
        
         String ss2 = "cName		cCode		createDate
";
            ss2 += "dbc券88		111188		2017-05-14
";
            ss2 += "zc券88		111199		2017-05-14
";
            
         createZip(zos,"result7.txt",ss2.getBytes());
         
//                zos.flush();
        //外置
        zos.closeEntry();
        zos.close();
    }

    private static void createZip(ZipOutputStream zos,String fileName,byte[] b) {
        try {
            // //create zip
            zos.putNextEntry(new ZipEntry(fileName));
            // set the declear
            zos.setComment("by zip test!");
            zos.write(b, 0, b.length);     //直接生成zip文件.跳过txt步骤
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
原文地址:https://www.cnblogs.com/simpledev/p/6854120.html