码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-05-14 22:20:46      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:length   etc   log   code   try   filename   put   stream   oid   

/**
     * @param args
     */
    public static void main(String[] args) throws Exception{
        ZipOutputStream zos = null;
         zos = new ZipOutputStream(new FileOutputStream("c:\\temp7.zip"));
         
         String ss = "cName\t\tcCode\t\tcreateDate\n";
            ss += "dbc券99\t\t111188\t\t2017-05-14\n";
            ss += "zc券99\t\t111199\t\t2017-05-14\n";
            
         createZip(zos,"temp7.txt",ss.getBytes());
        
         String ss2 = "cName\t\tcCode\t\tcreateDate\n";
            ss2 += "dbc券88\t\t111188\t\t2017-05-14\n";
            ss2 += "zc券88\t\t111199\t\t2017-05-14\n";
            
         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();
        }
    }

 

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

标签:length   etc   log   code   try   filename   put   stream   oid   

原文地址:http://www.cnblogs.com/simpledev/p/6854120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!