读写ZIP文件
String zipFile = /D:/+ ".zip";
StringOperator.zip(filePath, zipFile);
InputStream is = null;
OutputStream os = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
response.setCharacterEncoding("utf-8");
response.addHeader("Content-disposition", "attachment;filename=" + folderFileName + ".zip");
is = new FileInputStream(zipFile);
bis = new BufferedInputStream(is);
os = response.getOutputStream();
bos = new BufferedOutputStream(os);
int read = 0;
byte[] bytes = new byte[8072];
while((read = bis.read(bytes, 0, bytes.length)) != -1){
bos.write(bytes, 0, read);
}
bos.flush();
} catch (Exception e) {
e.printStackTrace();
}finally{
bos.close();
os.close();
bis.close();
is.close();
}
/**
* 压缩
*
* @param sourceFile
* 压缩的源文件 如: c:/upload
* @param targetZip
* 生成的目标文件 如:c:/upload.zip
*/
public static void zip(String sourceFile,String targetZip){
Project prj = new Project();
Zip zip = new Zip();
zip.setProject(prj);
zip.setDestFile(new File(targetZip));//设置生成的目标zip文件File对象
FileSet fileSet = new FileSet();
fileSet.setProject(prj);
fileSet.setDir(new File(sourceFile));//设置将要进行压缩的源文件File对象
zip.addFileset(fileSet);
zip.execute();
}
读写ZIP文件的更多相关文章
- python读写zip文件
zipfile.ZipFile(fileName[, mode[, compression[, allowZip64]]]) fileName是没有什么疑问的了. mode和一般的文件操作一样,'r' ...
- 【.NET深呼吸】Zip文件操作(2):动态生成Zip文档
通过前面一篇烂文的介绍,大伙儿知道,ZipArchive类表示一个zip文档实例,除了用上一篇文章中所列的方法来读写zip文件外,还可以直接通过ZipArchive类,动态生成zip文件. 文件流操作 ...
- JAVA核心技术I---JAVA基础知识(二进制文件读写和zip文件读写)
一:二进制文件读写 (一)写文件 –先创建文件,写入数据,关闭文件 –FileOutputStream, BufferedOutputStream,DataOutputStream –DataOutp ...
- 读写ZIP&JAR文件
1. ZipEntry 是包括目录的,也就是目录也被当做是一个单独的Entry,在列出它下面的文件之前先列出这个directory entry. 这个在解压ZIP文件的的时候特别有用,我们要先创建这个 ...
- 【.NET深呼吸】Zip文件操作(1):创建和读取zip文档
.net的IO操作支持对zip文件的创建.读写和更新.使用起来也比较简单,.net的一向作风,东西都准备好了,至于如何使用,请看着办. 要对zip文件进行操作,主要用到以下三个类: 1.ZipFile ...
- Orchard官方文档翻译(三) 通过zip文件手动安装Orchard
原文地址:http://docs.orchardproject.net/Documentation/Manually-installing-Orchard-zip-file 想要查看文档目录请用力点击 ...
- PHP 解压zip文件的函数封装
/** * zip文件解压 * * @param $zipFilePath zip文件的路径,可以不加zip文件后缀.如果其他类型的文件伪装成zip解压也会失败 * @param $directory ...
- Python使用openpyxl读写excel文件
Python使用openpyxl读写excel文件 这是一个第三方库,可以处理xlsx格式的Excel文件.pip install openpyxl安装.如果使用Aanconda,应该自带了. 读取E ...
- Android 解压zip文件你知道多少?
对于Android常用的压缩格式ZIP,你了解多少? Android的有两种解压ZIP的方法,你知道吗? ZipFile和ZipInputStream的解压效率,你对比过吗? 带着以上问题,现在就开始 ...
随机推荐
- 详解Linux安装GCC方法
转载自:http://blog.csdn.net/bulljordan23/article/details/7723495/ 下载: http://ftp.gnu.org/gnu/gcc/gcc-4. ...
- MyBatis SQL xml处理小于号与大于号
MyBatis SQL xml处理小于号与大于号 当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台 ...
- 【freemaker】之eclipse安装freemaker-IDE
eclipse安装插件一般我喜欢手动安装,有种可控的感觉! 首先需要下载freemaker-IDEhttp://freemarker-ide.sourceforge.net/ 下载之后解压得到 在ec ...
- 嵌入式应用中CGI编程中POST、GET及环境变量详解
原载地址:http://3633188.blog.51cto.com/3623188/828095 1.POST和GET 一个CGI程序在于服务器之间的信息传输和数据传输一般通过两种方法,即 ...
- C#对数组去重
#region ArrayList的示例应用 /// 方法名:DelArraySame /// 功能: 删除数组中重复的元素 /// </summary> /// <param na ...
- purgeIdleCellConnections: found one to purge conn = 0x1e09f7d0
purgeIdleCellConnections: found one to purge conn = 0x1e09f7d0 你在iOS6下使用3G网络时可能会遇到这条log,不用紧张,这只是苹果的工 ...
- Redis数据库?-Redis的Virtual Memory介绍(转)
众所周知,Redis是一个内存数据库,和Memcached类似,所有数据存在内存中,当然,Redis有rdb和appendonlyfile两个落地文件,可以对断电停机等故障下的数据恢复做一些保证.但是 ...
- iphone dev 入门实例5:Get the User Location & Address in iPhone App
Create the Project and Design the Interface First, create a new Xcode project using the Single View ...
- IREP_SOA Integration WSDL概述(概念)
20150827 Created By BaoXinjian
- 2016 Multi-University Training Contest 5 Divide the Sequence
Divide the Sequence 题意: 给你一个序列A,问你最多能够分成多少个连续子序列,使得每个子序列的所有前缀和均不小于0 题解: 这题是比赛时候的水题,但我比的时候也就做出这一题, = ...