SpringBoot 遍历资源文件夹 打包后可用

Resource[] resources = ResourcePatternUtils.getResourcePatternResolver(resourceLoader)
                .getResources("classpath:decode/*.json");
        for(Resource resource: resources){
            InputStream inputStream = resource.getInputStream();
            String content = new BufferedReader(new InputStreamReader(inputStream))
                    .lines().collect(Collectors.joining(System.lineSeparator()));
            System.out.println(content);
        }

需注入resourceLoader

posted @ 2024-04-22 09:56  迷路的圆  阅读(46)  评论(0编辑  收藏  举报