java讀取properties文件

Java項目經常使用properties文件,提供一個讀取properties文件工具類,可以方便獲取文件內容,

package com.framelib.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 配置文件讀取
 * Title:ConfigUtils
 * Description:
 * @Create_by:caozhifei
 * @Create_date:2014-04-04
 * @Last_Edit_By:
 * @Edit_Description
 * @version: 1.0
 *
 */
public class ConfigUtils  {
	private static Logger logger = LoggerFactory.getLogger(ConfigUtils.class);
	
	
	/**
	 * 讀取Properties配置文件
	 * Title:
	 * Description:
	 * @Create_by:Zhangy Yan
	 * @Create_date:2013-11-30
	 * @Last_Edit_By:
	 * @Edit_Description
	 * @Create_Version:ShareWithUs 1.0
	 */
	public static Properties getPropertiesFile(String confPath){
		InputStream is = ConfigUtils.class.getClassLoader().getResourceAsStream(confPath);
		Properties prop = new Properties();
	    try {   
		    prop.load(is);
		    is.close();
		    logger.debug("load config file success ,filePath is "+confPath);
	    } catch (IOException ex) {   
	    	logger.error("讀取配置文件失敗,配置文件路徑爲:"+confPath, ex);
	    }
	    return prop;

	}
	
 
 

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章