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文件的更多相关文章

  1. java 生成zip文件并导出

    总结一下,关于Java下载zip文件并导出的方法,浏览器导出. String downloadName = "下载文件名称.zip"; downloadName = Browser ...

  2. POI以SAX方式解析Excel2007大文件(包含空单元格的处理) Java生成CSV文件实例详解

    http://blog.csdn.net/l081307114/article/details/46009015 http://www.cnblogs.com/dreammyle/p/5458280. ...

  3. Java生成CSV文件实例详解

    本文实例主要讲述了Java生成CSV文件的方法,具体实现步骤如下: 1.新建CSVUtils.java文件: package com.saicfc.pmpf.internal.manage.utils ...

  4. Java生成压缩文件(zip、rar 格式)

    jar坐标: <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant</ar ...

  5. java生成zip压缩文件,解压缩文件

    1.生成zip public static void main(String[] args) { try { // testZip("c:\\temp.txt", "c: ...

  6. java生成压缩文件

    在工作过程中,需要将一个文件夹生成压缩文件,然后提供给用户下载.所以自己写了一个压缩文件的工具类.该工具类支持单个文件和文件夹压缩.放代码: import java.io.BufferedOutput ...

  7. java压缩zip文件中文乱码问题(转——作者:riching)

    本人遇到了同样的问题,用了以下方案,奇迹般的解决了.我很纳闷为什么,经理说:好读书,不求甚解,不要问为什么... 用java来打包文件生成压缩文件,有两个地方会出现乱码 1.内容的中文乱码问题,这个问 ...

  8. java压缩zip文件中文乱码问题

    用java来打包文件生成压缩文件,有两个地方会出现乱码 1.内容的中文乱码问题,这个问题网上很多人给出了解决方法,两种:修改sun的源码:使用开源的类库org.apache.tools.zip.Zip ...

  9. java生成zip包兼容Linux

    /* 这个方法只用在windows中用服务器为Linux就不行 */ package common.util; import java.io.File;import java.io.FileInput ...

随机推荐

  1. how to use fiddler and wireshark to decrypt ssl

    原文地址: http://security14.blogspot.jp/2010/07/how-to-use-fiddler-and-wireshark-to.html Requirements2 C ...

  2. 【jvm】java查看内存使用jmap,jstat和jstack使用 ,docker启动服务下查看jvm使用情况

    [声明,如果是docker启动的服务,可以在进入容器内后,再使用如下命令操作] [docker exec -it 容器ID  /bin/bash     即可进入容器内] [如果不是docker启动的 ...

  3. cocos2d-x CC_SYNTHESIZE_READONLY

    //定义一个只读属性Label,在类定义中可以使用this->getLabel来访问     CC_SYNTHESIZE_READONLY(cocos2d::CCLabelTTF*,_label ...

  4. android 读取 raw 中的文件。

    file.getParentFile().mkdir(); file.createNewFile(); InputStream inputStream = context.getResources() ...

  5. tomcat server.xml maxPostSize=0 导致 果post表单收不到参数解决方案

  6. TextKit简单示例

    TextKit简单示例 效果 源码 https://github.com/YouXianMing/Animations // // TextKitLoadImageController.m // An ...

  7. 【转】解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题

    本文来自:http://blog.csdn.net/wulianghuan/article/details/11548373,感谢原作者的分享. 目标是读取SD卡中的图片并且展示出来 主要思路是通过一 ...

  8. windows 安装ninja

    ninja连接: https://ninja-build.org/ https://github.com/ninja-build/ninja 下载安装包: https://github.com/nin ...

  9. git clone报错:“server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none”

    I can push by clone project using ssh, but it doesn't work when I clone project with https. it shows ...

  10. PHP读写INI文件

    读INI文件 public function readini($name) { if (file_exists(SEM_PATH.'init/'.$name)){ $data = parse_ini_ ...