excel模板下载工具类
public static void dowlondTemplate(HttpServletResponse response,String fileName){
try {
org.springframework.core.io.Resource resource = new ClassPathResource(fileName);
File file = resource.getFile();
String filename = resource.getFilename();
InputStream inputStream = new FileInputStream(file);
//强制下载不打开
response.setContentType(“application/force-download”);
OutputStream out = response.getOutputStream();
//使用URLEncoder来防止文件名乱码或者读取错误
response.setHeader(“Content-Disposition”, “attachment; filename=”+ URLEncoder.encode(filename, “UTF-8”));
int b = 0;
byte[] buffer = new byte[1000000];
while (b != -1) {
b = inputStream.read(buffer);
if(b!=-1) out.write(buffer, 0, b);
}
inputStream.close();
out.close();
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
**excel模板下载工具类**
最新推荐文章于 2022-05-13 15:17:43 发布