打开本地文件的属性查看路径
Java代码
@ApiOperation(value = "文件下载", notes = "导出excel表格")
@RequestMapping(value = "/clientDownload", method = RequestMethod.GET)
public void orderFile(ModelMap model, HttpServletRequest request, HttpServletResponse response, @RequestParam String exeName) {
InputStream inputStream = null;
//设置下载文件的名字
exeName=exeName+".xls";
try{
//String contextRealPath = FilePropertyUtil.getFilePathProperty().getProperty("temPath");//request.getSession().getServletContext().getRealPath("/");
//这里是本地文件的路径
inputStream = new FileInputStream(new File("文件的路径记得加后缀C:\Users\\antong.xls"));
// 清空response
response.reset();
// 设置response的Header
response.addHeader("Content-Disposition", "attachment;filename=" + new String(exeName.getBytes("gb2312")));
byte[] b = new byte[1024];
int len = -1;
OutputStream outputStream = response.getOutputStream();
while ((len = inputStream.read(b)) !=-1) {
/** 向输出流中输出pdf文件 **/
outputStream.write(b, 0, len); //读取字节,从0到len长度
}
inputStream.close();
//setSuccess(model);
}catch(Exception e){
e.printStackTrace();
if(inputStream!=null){
try {
inputStream.close();
} catch (IOException e1) {
}
}
//setFailure(model);
}
}
然后浏览器访问
然后就可以下载了