直接使用Java的资源绑定,可以直接获取到属性
public class JavaReadProDemo {
public static void main(String[] args) {
ResourceBundle dbPro = ResourceBundle.getBundle("db");
String dricerclass = dbPro.getString("dricerclass");
String url = dbPro.getString("url");
String username = dbPro.getString("username");
String password = dbPro.getString("password");
System.out.println(dricerclass);
System.out.println(url);
System.out.println(username);
System.out.println(password);
}
}
db.properties
dricerclass=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@192.168.0.1:1521:orcl
username=scott
password=tiger
输出结果
oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@192.168.0.1:1521:orcl
scott
tiger