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压缩文件
最新推荐文章于 2022-10-25 17:38:17 发布