//下载resource文件夹下面的document文件夹下的模板
public JsonList orderDownloadTemplate(String strJson,String token,JsonList json)
throws Exception{
String fn = new String("文件名.xls".getBytes("GBK"), "iso8859-1");
String filePath = this.getClass().getClassLoader().
getResource("document").getPath();//获取文件路径
filePath = filePath + "/orderStaffTemplate.xls";
getResponse().setContentType("APPLICATION");
getResponse().setHeader("Content-Disposition",
"attachment; filename=" + fn);
File file=new File(filePath);
FileInputStream fis = new FileInputStream(file);
byte[] bytesArray = new byte[(int) file.length()];
fis.read(bytesArray);
fis.close();
getResponse().getOutputStream().write(bytesArray);
return null;
}
spring boot下载文件
最新推荐文章于 2025-02-11 13:20:17 发布
本文介绍了一个使用Java实现的导出Excel模板的方法,通过读取资源文件夹下的模板文件,将其作为响应返回给客户端,实现了文件的下载功能。此方法适用于需要提供Excel模板下载的Web应用。
2007

被折叠的 条评论
为什么被折叠?



