zoukankan      html  css  js  c++  java
  • Java 生成ZIP文件

     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();
        }
  • 相关阅读:
    SSH--1
    oracle---jdbctest--laobai
    oracle---jdbc--laobai
    oracle--知识点汇总2---laobai
    Tomcat_Java Web_内存溢出总结
    单例经典示例
    线程--demo3
    网络通信---示例
    验证码---示例
    java--绘图
  • 原文地址:https://www.cnblogs.com/yshyee/p/7399713.html
Copyright © 2011-2022 走看看