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

缓冲流上载文件

2013-03-14 
缓冲流下载文件此处demo为下载pdf文件。response.setContentType(application/pdf)response.setHeader(

缓冲流下载文件

此处demo为下载pdf文件。

response.setContentType("application/pdf");

response.setHeader("Content-disposition", "attachment;filename=epolicy.pdf");

BufferedOutputStream outp = null;

BufferedInputStream in = null;

String filenamedownload = "";

try {

outp = new BufferedOutputStream(response.getOutputStream());

in = new BufferedInputStream( new FileInputStream(filenamedownload) );

byte[] b = new byte[1024]; int i = 0; while ((i = in.read(b)) > 0) { outp.write(b, 0, i); }

} catch (IOException e) {

log.error("下载文件出错,请稍后再试!", e);

} finally {

if(outp != null){ outp.flush(); outp.close(); } if(in != null){ in.close(); }

}

热点排行