-
文件位置
-
代码实现
/**
* 下载
* @return
*/
@RequestMapping("/down")
@ResponseBody
public void down(HttpServletResponse response) throws Exception {
//获取文件路径
String path = ClassUtils.getDefaultClassLoader().getResource("").getPath()+ "static/wj/工作表.xlsx";
System.out.println("path = " + path);
String fileName = path.substring(path.lastIndexOf("/") + 1);
File file = new File(path);
// 将文件名称进行编码
response.setHeader("content-disposition","attachment;filename=" + URLEncoder.encode(fileName,"UTF-8"));
response.setContentType("content-type:octet-stream");
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));
OutputStream outputStream = response.getOutputStream();
byte[] by = new byte[1024];
int len=0;
while ((len = inputStream.read(by)) != -1){
outputStream.write(by,0,len);
}
inputStream.close();
outputStream.close();
}