javaweb,文件下载设置Header

来源:互联网 发布:js判断等于空字符串 编辑:程序博客网 时间:2024/05/16 15:42
FileInputStream is = new FileInputStream(new File("C:\\pmchelp.pdf"));
resp.setContentType("application/octet-stream"); 
resp.setHeader("Content-Disposition", "attachment;fileName="+"20170315160623.pdf"); 
ServletOutputStream sos = resp.getOutputStream();
byte[] bytes = new byte[1024];int count = 0; 
while ((count = is.read(bytes)) != -1) { 
     sos.write(bytes, 0, count); 

is.close();
sos.close();
0 0
原创粉丝点击