您的位置:首页 > 其它

读取配置文件

2015-08-03 13:41 405 查看
public class ReadConfig {
	
	public static Properties dbproperties = new Properties();
	private static Logger logger = Logger.getLogger(ReadConfig.class);
	
	static {
		loadsProperties();
	}
	
	static public void loadsProperties(){
        
        InputStream is = ReadConfig.class.getResourceAsStream("/parameters.properties");
        
        try {
            dbproperties.load(is);
        }
        catch (Exception e) {
        	logger.error("不能读取属性文件. ", e);
        }
        
    }

}


该例子中,配置文件parameters.properties存在于src目录下

调用:

String myBlogName = ReadConfig.dbproperties.getProperty("hqq1007")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: