URL url = Test.class.getClassLoader().getResource("templates/" + fileName);
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
String filePath = url.toURI().getPath();
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition",
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
FileUtils.writeBytes(filePath, response.getOutputStream());
this.getClass().getClassLoader().getResource(“/”).getPath()+”res”
得到的路径如果有空格会把空格编译成%20,导致识别不了文件路径
解决办法:
在getResource(“/”).toURI().getPath()