1.本地使用ResourceUtils.getFile没有任何问题,打成jar包后部署到服务器上报错
错误原因:
ResouceUtils.getFile()是专门用来加载非压缩文件类型的资源的,所以它根本不会去读取jar包中的资源,本地之所以没事是因为本地访问的不是jar而是直接编译的,
解决方法:
要想读取jar包中的文件,只能通过流来进行读取。可以使用new ClassPathResource(filepath);
代码
public void downloadCompanyTemplate(HttpServletRequest request, HttpServletResponse response, String fileType)
throws IOException
{
InputStream inputStream = null;
String filename = null;
ClassPathResource resource = = new ClassPathResource(filepath);
filename = resource.getFilename();
inputStream = resource.getInputStream();
getWordByInputStream(response, inputStream, filename);
}
public void getWordByInputStream(HttpServletResponse response, InputStream
inputStream, String filename) throws UnsupportedEncodingException
{
BufferedInputStream bis = nu