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

java 通过 Properties 读取数据库配置 .properties 文件的使用。

2015-09-02 00:00 836 查看
摘要: java 通过 Properties 读取数据库配置 .properties 文件的使用。

system.properties

user=root
password=root
jdbcUrl=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8;
driverClass=com.mysql.jdbc.Driver

调用方法:

public void getProperties(){
Properties prop = new Properties();
try {
prop.load(new BufferedInputStream(new FileInputStream(this.getClass().getResource("/").getPath().substring(1)+"system.properties")));
System.out.println(prop.getProperty("user"));
System.out.println(prop.getProperty("password"));
System.out.println(prop.getProperty("jdbcUrl"));
System.out.println(prop.getProperty("driverClass"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Properties