package JDBC;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesMethod {
public static void main(String[] args) throws IOException {
/*
* 用来读取 properties 文件
* 实现Map,内部使用散列表,key 和 value 都是 String 类型
*/
Properties ppt = new Properties();
// System.out.println(ppt);
System.out.println(ppt.size());
System.out.println(ppt.isEmpty());
// 利用 load 读取文件
InputStream in = PropertiesMethod.class.getClassLoader().getResourceAsStream("db.properties");
ppt.load(in);
// System.out.println(ppt);
System.out.println(ppt.size());
System.out.println(ppt.getProperty("jdbc.url"));
System.out.println(ppt.getProperty("jdbc.user"));
}
}
# db.properties
jdbc.driver = oracle.jdbc.OracleDriver
jdbc.url = jdbc:oracle:thin:@localhost:1521:oracle
jdbc.user = system
jdbc.password = Xr20180101
jdbc.initialSize = 20
jdbc.maxActive = 100
jdbc.maxIdle = 20
jdbc.minIdle = 10