class path resource [classpath:xxx.docx] cannot be opened because it does not exist
class path resource [classpath:xxx.docx] cannot be opened because it does not exist 这个报错是文件读取不到。
解决办法:
//本地读取:
File tmpFile = null;
try {
tmpFile = ResourceUtils.getFile("classpath:demo.docx");
inputStream = new FileInputStream(tmpFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//jar读取:
ClassPathResource classPathResource = new ClassPathResource("classpath:demo.docx");
try {
inputStream = classPathResource.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}