首页 > 编程语言 > 详细

Java 生成ZIP文件

时间:2017-08-20 13:31:25      阅读:222      评论:0      收藏:0      [点我收藏+]
 public static byte[] fileToZip(){
        ZipOutputStream append = null;
        
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        
        try {
            append = new ZipOutputStream(bos);
            
            ZipEntry e = new ZipEntry("request.xml");
            append.putNextEntry(e);
            append.write(filteToByte("G:\\tmp\\request.xml"));
            append.closeEntry();
            
            e = new ZipEntry("CONTENT\\content.xml");
            append.putNextEntry(e);
            append.write(filteToByte("G:\\tmp\\content.xml"));
            append.closeEntry();
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        } finally{
            if(null != append){
                try {
                    append.close();
                } catch (IOException ex) {
                    Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
        return bos.toByteArray();
    }

 

Java 生成ZIP文件

原文:http://www.cnblogs.com/yshyee/p/7399713.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!