通过配置文件的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;
    }

 

posted @ 2018-06-06 17:50  逝年的我们  阅读(337)  评论(0编辑  收藏  举报