java获取application.properties和application.yml配置文件信息

  public static void main(String[] args) {
        String result=getProjectConfig("max-file-size");
        System.out.println(result);
    }

    public static String getProjectConfig(String key) {
        Properties pros = new Properties();
        String value = "";
        try {

            pros.load(new InputStreamReader(PropertiesUtil.class.getResourceAsStream("/application.yml"), "UTF-8"));
            value = pros.getProperty(key);
        } catch (Exception e) {
        return e.getMessage();
        }
        return value;
    }

猜你喜欢

转载自www.cnblogs.com/Revival-of-everything/p/10788812.html