out.clearBuffer();
//获取文件地址
String fileName = request.getParameter("f");
File file = new File(fileName);
response.setContentType("application/x-download");//设置为下载application/x-download
response.addHeader("Content-Disposition","attachment;filename=" + file.getName()+".zip");
FileInputStream in = null;
OutputStream outp = null;
GZIPOutputStream gzout = null;
try{
in = new FileInputStream(file);
outp = response.getOutputStream();
gzout = new GZIPOutputStream(outp);
byte[] buf = new byte[1024];
int i = 0;
while ((i = in.read(buf)) != -1){
gzout.write(buf,0,i);
}
outp.flush();
}catch (Exception e){
System.out.println("Error!");
e.printStackTrace();
}finally {
if(gzout != null) gzout.close();
if(outp != null) outp.close();
if(in != null) in.close();
}
return;
详细解决方案
jsp - 上载gzip压缩文件
热度:324 发布时间:2012-09-23 10:28:11.0
相关解决方案
- 关于http请求中Accept-Encoding: gzip, deflate,该如何处理
- 关于http请求中Accept-Encoding: gzip, deflate解决方案
- 【转】Java 高性能Web 开发(五)-GZIP 压缩
- nginx gzip 静态资料压缩
- gzip下令:压缩文件
- 怎么整站开启php zlib(gzip)压缩输出
- tar命令出错: gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error
- pb 压缩文件 有关问题
- tar,gzip
- java 压缩文件 zip
- python requests.get(): Received response with content-encoding: gzip
- Linux常用命令之压缩解压缩命令详解(gzip、gunzip、bzip2、bunzip2、tar)
- 如何整站开启php zlib(gzip)压缩
- Tomcat gzip 的配置
- redhat Linux系统 tar、gzip 、zip等压缩命令
- gzip/bzip2/xz/tar包的文件压缩与解压缩
- gzip 小结
- Accept-Encoding: gzip,deflate + libcurl + rt5350
- zip bzip2 gzip xz tar文件解压缩
- linux 下 压缩文件
- Linux系统下的归档和压缩(tar,gzip)详解
- SpringBoot - 前后端大数据压缩传输 Gzip 解决方案(手动版)