Java中文件下載
/*附件下載*/
@RequestMapping(value="/downFile")
public void downFile(HttpServletResponse response){
try {
OutputStream os = null;
//獲取文件名稱
String filename = new String(jjkjGggl.getAccName().getBytes(),"ISO-8859-1");
//添加文件後綴
filename = filename+jjkjGggl.getAccType();
//附件存在 設置文件頭:最後一個參數是設置下載文件名
response.setHeader("Content-Disposition", "attachment;filename="+filename);
os = response.getOutputStream();
byte[] b = jjkjGggl.getAccContent();
os.write(b);
os.flush();
os.close();
}
} catch (Exception e) {
logger.info("<--附件下載出現異常-->"+e);
}
}
Java中文件下載