您的位置:首页 > 运维架构

Properties 文件 读取 的几种方式

2011-11-10 22:35 429 查看
private static final String CONFIG_PROPERTIES = "ipConfig.properties"; // properties 文件路径



==================================================================================================================

第一种方式

InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(CONFIG_PROPERTIES);   
Properties p = new Properties();   
try {   
	p.load(inputStream);   
} catch (IOException e1) {   
	e1.printStackTrace();   
}   
p.getProperty(key);



==================================================================================================================

第二种方式

InputStream inStream = Constant.class.getResourceAsStream(CONFIG_PROPERTIES);   
Properties prop = new Properties();   
try {   
	prop.load(inStream);   
} catch (IOException e) {   
	e.printStackTrace();   
}   
prop.getProperty(key);



==================================================================================================================

第三种方式

Properties prop = new Properties();   
try {   
	FileInputStream inStream = new FileInputStream(CONFIG_PROPERTIES);   
	prop.load(inStream);   
} catch (IOException e) {   
	e.printStackTrace();   
}   
prop.getProperty(key);


==================================================================================================================

第四种方式

ResourceBundle resourceBundle = ResourceBundle.getBundle("jdbc");   
resourceBundle.getString(key);




@@
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: