美文网首页
springboot 读取resources路径下的json文件

springboot 读取resources路径下的json文件

作者: zxbyh | 来源:发表于2023-04-07 16:16 被阅读0次

    springboot 读取resources路径下的json文件并转换为json。

      @Resource
      protected ResourceLoader resourceLoader;
    
      private JSONObject _getConfJoFromJsonFile(){
            try {
                var resource = resourceLoader.getResource("classpath:conf.json");
                String jsonStr = new String(resource.getInputStream().readAllBytes());
                System.out.println(jsonStr);
                return(JSONObject.parse(jsonStr));
            }
            catch (IOException ioException){
                System.out.println(ioException.getMessage());
                Asserts.fail(-1001,"读取conf.json出错。"+ioException.getMessage());
                return JSONObject.of();
            }
        }
    

    相关文章

      网友评论

          本文标题:springboot 读取resources路径下的json文件

          本文链接:https://www.haomeiwen.com/subject/rhnpddtx.html