3 回答

TA贡献1111条经验 获得超0个赞
因为当打包的 uber-jar 中不存在您的资源时,类路径有问题。使用这样的解决方案
String fuu = "";
ClassPathResource classPathResource = new ClassPathResource("static/foo.txt");
try {
byte[] binaryData = FileCopyUtils.copyToByteArray(classPathResource.getInputStream());
fuu = new String(binaryData, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}

TA贡献1829条经验 获得超13个赞
试试这个
IOUtils.toString(new InputStreamReader(this.getClassLoader().getResourceAsStream("fileName.json")))
OR
new InputStreamReader(new ClassPathResource("fileName.json", this.getClassLoader()).getInputStream())
不要使用FileReader或File
使用InputStreamReader , InputStream等
添加回答
举报