1. 程式人生 > >springboot獲取專案專案中的檔案

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);
}