通过配置文件的key得值

Posted 逝年的我们

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过配置文件的key得值相关的知识,希望对你有一定的参考价值。

    public static String TM_API_SERVER_HOST = PropertiesUtil.getProperty("config/im.properties", "TIM_HOST");

    public static String getProperty(String resource, String key) {
        Properties properties = PropertiesUtil.getProperties(resource);
        return properties.getProperty(key);
    }

    /**
     * 读取properties文件
     * 
     * @param resource
     *            文件名称
     * @return
     */
    public static Properties getProperties(String resource) {

        Properties properties = new Properties();
        try {
            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream

            (resource);
            properties.load(is);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            throw new RuntimeException(ioe);
        }
        return properties;
    }

 

以上是关于通过配置文件的key得值的主要内容,如果未能解决你的问题,请参考以下文章