您的位置:首页 > 编程语言 > Java开发

java 读取 properties 属性文件

2014-12-28 09:24 381 查看
<pre name="code" class="java">/**
*读取properties属性文件
* @throws IOException
*/
@Test
public void testReadProperties() throws IOException{
//创建 Properties
Properties prop = new Properties();
//获得输入流
InputStream in =
getClass().getClassLoader().getResourceAsStream("resources/jdbc.properties");
//Reads a property list (key and element pairs) from the input byte stream.
prop.load(in);
//Searches for the property with the specified key in this property list.
String user = prop.getProperty("user");
System.out.println(user);
}
jdbc.properties

driver=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/showPictures
user=root
password=wyc226



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