springboot导入数据的时候,为了方便用户下载模板,会在项目资源目录底下放模板。当项目用开发工具时,以下代码可以正常下载文件
FileDownLoadUtil.download(this.getClass().getResource("excel").getPath()
+"/"+"文件名.xlsx",response,true);
/**
* 文件下载接口
* @param response
* @param isOnLine 传入true,表示打开,但是打开的是浏览器能识别的文件,比如图片、pdf,word等无法打开
* 传入false,只是下载,如果不传入这个参数默认为false
* @throws Exception
*/
@Deprecated
public static void download(String filePath, HttpServletResponse response,boolean isOnLine)throws Exception{
File f = new File(filePath);
if (!f.exists()) {
response.sendError(1, "File not found!");
return;
}
String fileName = f.getName().replace("1","").replace("2","");
fileName = new String(fileName.getBytes("UT