java讀取配置文件

gww3 9年前發布 | 927 次閱讀 Java
/**
     * 讀取配置文件
     * @param file
     * @return
     */
    public static PropertiesConfiguration loadConfig(String file){
        PropertiesConfiguration config = null;
        try {
            config = new PropertiesConfiguration(file);
            config.setEncoding("UTF-8");
            config.setReloadingStrategy(new FileChangedReloadingStrategy());
            config.setAutoSave(true);
            logger.info("加載配置文件成功...");
        } catch (ConfigurationException e) {
            logger.info("加載配置文件失敗,異常信息:"+e.getLocalizedMessage());
        }
        return config;
    }

public static Configuration config = loadConfig("config.properties");
ConfigUtils.config.getString("weixin.app_id")
 本文由用戶 gww3 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!