MyException - 我的异常网
当前位置:我的异常网» Web前端 » 读取properties资料类

读取properties资料类

www.MyException.Cn  网友分享于:2013-02-20  浏览:3次
读取properties文件类
package com.bsi.scserc.bi.util;

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

import org.apache.log4j.Logger;

public class PropertyFactory {
	static Logger logger = Logger.getLogger(PropertyFactory.class);
	
	public static Properties getIndexProperties(){
		return getProperties("/properties/index.properties");
	}
	
	public static Properties getWebServieProperties(){
		return getProperties("/properties/webservice.properties");
	}
	
	public static Properties getHqlProperties(){
		return getProperties("/properties/hql.properties");
	}
	
	public static Properties getPageUrlProperties(){
		return getProperties("/properties/pageurl.properties");
	}
	
	public static Properties getProperties(String propFile){
		Properties p = null;
		try{
			InputStream in = PropertyFactory.class.getClassLoader().getResourceAsStream(propFile);
			p = new Properties();
			p.load(in);
		}catch(Exception e){
			logger.error("Can not load "+propFile + " properties file.");
		}
		return p;
	}
}
使用:PropertyFactory.getPageUrlProperties().getProperties("pagurl.properties文件中的key值");

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有