当前位置: 代码迷 >> JavaScript >> jsp - 上载gzip压缩文件
  详细解决方案

jsp - 上载gzip压缩文件

热度:324   发布时间:2012-09-23 10:28:11.0
jsp - 下载gzip压缩文件
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;


  相关解决方案