javaweb,文件下载设置Header

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();

你可能感兴趣的:(java)