首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jsp - 上载gzip压缩文件

2012-09-23 
jsp - 下载gzip压缩文件out.clearBuffer()//获取文件地址String fileName request.getParameter(f)F

jsp - 下载gzip压缩文件

out.clearBuffer();//获取文件地址String fileName = request.getParameter("f");File file = new File(fileName);response.setContentType("application/x-download");//设置为下载application/x-downloadresponse.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;


热点排行