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

猜你喜欢

转载自www.cnblogs.com/wwwcf1982603555/p/9146460.html
今日推荐