@Test
// 读取配置文件方式一:ResourceBundle
public void readMethod1() {
ResourceBundle rb = ResourceBundle.getBundle("jdbc");
String driver = rb.getString("driver");
String url = rb.getString("url");
String user = rb.getString("user");
String password = rb.getString("password");
System.out.println(driver + "\t" + url + "\t" + user + "\t" + password);
}
@Test
// 读取配置文件方式二:用类加载器加载
public void readMethod2() throws IOException {
InputStream in = ReadProperties.class.getClassLoader()
.getResourceAsStream("jdbc.properties");
Properties p = new Properties();
p.load(in);
String driver = p.getProperty("driver");
String url = p.getProperty("url");
String user = p.getProperty("user");
String password = p.getProperty("password");
System.out.println(driver + "\t" + url + "\t" + user + "\t" + password);
}
} |
|