欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【解决方案】springboot 打jar包后启动,resource下配置文件找不到

程序员文章站 2022-05-04 17:30:54
...
public static String getFileContent(String fileName) {
        StringBuilder sb = new StringBuilder();
        try {
            ClassPathResource classPathResource = new ClassPathResource(fileName);

            InputStream stream = classPathResource.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8.name()));
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
            return sb.toString();
        } catch (Exception e) {
            return sb.toString();
        }
    }