import java.io.File;

  import java.io.FileInputStream;

  import java.io.FileOutputStream;

  import java.util.zip.ZipEntry;

  import java.util.zip.ZipOutputStream;

  public class ZipOutputStreamDemo {

  public static void main(String[] args) throws Exception {

  byte[] buffer = new byte[1024];

  //生成的ZIP文件名为Demo.zip

  String strZipName = "Demo.zip";

  ZipOutputStream out = new ZipOutputStream(new FileOutputStream(strZipName));

  //需要同时下载的两个文件result.txt ,source.txt

  File[] file1 = {new File("result.txt"),new File("source.txt")};

  for(int i=0;i<file1.length;i++) {

  FileInputStream fis = new FileInputStream(file1[i]);

  out.putNextEntry(new ZipEntry(file1[i].getName()));

  int len;

  //读入需要下载的文件的内容,打包到zip文件

  while((len = fis.read(buffer))>0) {

  out.write(buffer,0,len);

  }

  out.closeEntry();

  fis.close();

  }

  out.close();

  System.out.println("生成Demo.zip成功");

  }

Java实现文件自动打包成zip并下载的代码的更多相关文章

  1. 关于springmvc下服务器文件打包成zip格式下载功能

    关于springmvc下服务器文件打包成zip格式下载功能 2016年09月21日 11:22:14 toxic_guantou 阅读数:5731更多 个人分类: 技术点存储   版权声明:本文为博主 ...

  2. java批量下载,将多文件打包成zip格式下载

    现在的需求的: 根据产品族.产品类型,下载该产品族.产品类型下面的pic包: pic包是zip压缩文件: t_product表: 这些包以blob形式存在另一张表中: t_imagefile表: 现在 ...

  3. php将文件夹打包成zip文件

    function addFileToZip($path,$zip){    $handler=opendir($path); //打开当前文件夹由$path指定.    while(($filenam ...

  4. java将文件打包成ZIP压缩文件的工具类实例

    package com.lanp; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ja ...

  5. springboot中使用freemarker生成word文档并打包成zip下载(简历)

    一.设计出的简历模板图以及给的简历小图标切图         二.按照简历模板图新建简历word文件 :${字段名},同时将图片插入到word中,并将建好的word文件另存为xml文件:    三.直 ...

  6. 将多张图片打包成zip包,一起上传

    1.前端页面 <div class="mod-body" id="showRW" style="text-align: center;font- ...

  7. Springboot生成二维码并下载图片png支持打包成zip

    pom.xml <!--二维码--> <dependency> <groupId>com.google.zxing</groupId> <arti ...

  8. java中汉字自动转换成拼音

    java中汉字自动转换成拼音 1.需要下载jar包 pinyin4j.2.5.0.jar ,加入到WEB-INF下的lib里边,右键add to bulid path. 2.[代码]PinYinUti ...

  9. (原+转)ubuntu中将文件夹打包成iso的命令

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/8564483.html 参考网址: https://zhidao.baidu.com/question/ ...

随机推荐

  1. Proxy 代理模式 动态代理 cglib MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  2. Android -- 跳转应用市场评分

    Code Uri uri = Uri.parse("market://details?id="+getPackageName()); Intent intent = new Int ...

  3. javascript进行遍历

    javascript进行遍历 <!doctype html> <html lang="en"> <head> <meta charset= ...

  4. mysql 错误:1166 解决办法

    原因:检查字段里面是不是有空格,去掉就可以了

  5. 微信小程序 - 文字收缩与展开

    wxml <view class='containers'> <text class="content {{ellipsis?'ellipsis':'unellipsis' ...

  6. Ubuntu apt-get方式安装Subversion

    按照官方文档 http://subversion.apache.org/packages.html 使用apt-get安装方式: 1.安装Subversion: sudo apt-get instal ...

  7. mavern安装方法

    Installation Instructions Maven is a Java tool, so you must have Java installed in order to proceed. ...

  8. Unix时间戳转换

    import time   def timestamp_datetime(value):     format = '%Y-%m-%d %H:%M:%S'     # value为传入的值为时间戳(整 ...

  9. TP3.2 APP_DEBUG=false关闭调试后访问不了。页面错误!请稍后再试~

    在APP_DEBUG=true时是没问题的,在APP_DEBUG=false时才会出现找不到模板的问题.  经过排查可能是模板文件找不到问题,之前是这么写的. 改为这个就好了. ----------- ...

  10. eclipse Java compiler level does not match the version of the installed Java project facet.

      eclipse Java compiler level does not match the version of the installed Java project facet. Create ...