文件下载

/jsp页面/

计划书

${list.schemes} 下载

/Connection/
@RequestMapping("/xiazai")
public void xiazai(String schemes , HttpSession session, HttpServletResponse response){
String realPath = session.getServletContext().getRealPath(“uploads/scheme”);
File file =new File(realPath,schemes);
try (InputStream in =new FileInputStream(file);
OutputStream out=response.getOutputStream();
){
response.setContentType(“application/x-download”);
String encode = URLEncoder.encode(schemes, “UTF-8”);
response.addHeader(“Content-Disposition”, “attachment;fileName=” + schemes);
IOUtils.copy(in, out);
out.flush();
}catch (Exception e){
e.printStackTrace();
}
}

你可能感兴趣的:(java文件下载)