读取resource根目录下的配置文件---标准

//读取配置文件
//fileName="conf.json";
    public String getConf(String fileName) {
        String content="";
        try {
            //jsonFile = ResourceUtils.getFile("classpath:"+fileName);
            ClassPathResource resource = new ClassPathResource(fileName);
            InputStream stream = resource.getInputStream();
            content = IOUtils.toString(stream);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e) {
            logger.error("no file found!", e);
        }

        logger.info("配置文件:{}"+content);
        return content;
    }
原创文章 75 获赞 28 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_33999844/article/details/86223770