Java实现文件自动打包成zip并下载的代码
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并下载的代码的更多相关文章
- 关于springmvc下服务器文件打包成zip格式下载功能
关于springmvc下服务器文件打包成zip格式下载功能 2016年09月21日 11:22:14 toxic_guantou 阅读数:5731更多 个人分类: 技术点存储 版权声明:本文为博主 ...
- java批量下载,将多文件打包成zip格式下载
现在的需求的: 根据产品族.产品类型,下载该产品族.产品类型下面的pic包: pic包是zip压缩文件: t_product表: 这些包以blob形式存在另一张表中: t_imagefile表: 现在 ...
- php将文件夹打包成zip文件
function addFileToZip($path,$zip){ $handler=opendir($path); //打开当前文件夹由$path指定. while(($filenam ...
- java将文件打包成ZIP压缩文件的工具类实例
package com.lanp; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ja ...
- springboot中使用freemarker生成word文档并打包成zip下载(简历)
一.设计出的简历模板图以及给的简历小图标切图 二.按照简历模板图新建简历word文件 :${字段名},同时将图片插入到word中,并将建好的word文件另存为xml文件: 三.直 ...
- 将多张图片打包成zip包,一起上传
1.前端页面 <div class="mod-body" id="showRW" style="text-align: center;font- ...
- Springboot生成二维码并下载图片png支持打包成zip
pom.xml <!--二维码--> <dependency> <groupId>com.google.zxing</groupId> <arti ...
- java中汉字自动转换成拼音
java中汉字自动转换成拼音 1.需要下载jar包 pinyin4j.2.5.0.jar ,加入到WEB-INF下的lib里边,右键add to bulid path. 2.[代码]PinYinUti ...
- (原+转)ubuntu中将文件夹打包成iso的命令
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/8564483.html 参考网址: https://zhidao.baidu.com/question/ ...
随机推荐
- 在 Linux 中永久修改 USB 设备权限
问题 当我尝试在 Linux 中运行 USB GPS 接收器时我遇到了下面来自 gpsd 的错误.看上去 gpsd 没有权限访问 USB 设备(/dev/ttyUSB0).我该如何永久修改它在Linu ...
- POJ 1265:Area
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4725 Accepted: 2135 Description ...
- [Functional Programming] Fst & Snd, Code interview question
cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that ...
- hiberante 二级缓存设置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- Oracle体系结构四(学习笔记)
- 如何理解VB窗体中的scale类属性及width height属性之间的关系
如何理解VB窗体中的scale类属性及width height属性之间的关系 VB中的SCALEHIEGT,SCALEWIDTH,与窗体中的WIDTH,HEIGHT的区别及关系是许多VB初学者难以理解 ...
- 建maven私服nexus
1.下载nexus 2.配置java环境 3.安装 C:\Program Files\nexus\nexus-2.11.4-01\bin\jsw\windows-x86-64 4.配置 http:// ...
- ubuntu 下安装配置open-iscsi并自动挂载
1.安装open-iscsi apt-get install open-iscsi 2.发现iscsi-target(ISCSI服务器IP:192.168.1.104) iscsiadm -m dis ...
- 微服务(Microservices)
说在前面 好久没写博文了,心里痒痒(或许是换工作后,有点时间了吧). 近期好像谈论微服务的人比較多,也開始学习一下.可是都有E文.看起来半懂不懂的. Martinfowler的< ...
- 手动脱NsPacK壳实战
作者:Fly2015 这里脱壳的程序是吾爱破解培训的作业2,相较于作业1略微要强一点,可是仅仅要掌握了脱壳的ESP定律,脱这个Nspack壳并不难.只是还是蛮有意思的. 1.使用查壳软件对加壳的程序进 ...