springboot获取项目项目中的文件

https://stackoverflow.com/questions/25869428/classpath-resource-not-found-when-running-as-jar

String data = "";
ClassPathResource cpr = new ClassPathResource("static/file.txt");
try {
    byte[] bdata = FileCopyUtils.copyToByteArray(cpr.getInputStream());
    data = new String(bdata, StandardCharsets.UTF_8);
} catch (IOException e) {
    LOG.warn("IOException", e);
}

猜你喜欢

转载自blog.csdn.net/nihaoa50/article/details/84775758