今天做項(xiàng)目遇到一個需求,需要從后端獲取導(dǎo)入的模板文件,通過File file = new File("")獲取文件失敗,即使獲取到了,當(dāng)程序打成jar包時也會出現(xiàn)問題。
解決方案:
ClassPathResource classPathResource = new ClassPathResource("filePath");
InputStream inputStream = classPathResource.getInputStream();
參考鏈接:https://blog.csdn.net/wohaqiyi/article/details/80147999