gistfile1.txt #每一行后一定不能有空格db.driver = com.mysql.jdbc.Driverdb.url = jdbc:mysql://192.168.0.183:3306/zuipin?userunicode=truecharacterEncoding=utf8db.user = zuipindb.password = zuipin//简单读取 public void aa() { //创
#每一行后一定不能有空格 db.driver = com.mysql.jdbc.Driver db.url = jdbc:mysql://192.168.0.183:3306/zuipin?userunicode=true&characterEncoding=utf8 db.user = zuipin db.password = zuipin //简单读取 public void aa() { //创建配置对象 Properties pro = new Properties(); try { //加载配置文件 pro.load(Demo.class.getClassLoader().getResourceAsStream("db.properties")); System.out.println(pro.get("db.driver")); System.out.println(pro.get("db.url")); System.out.println(pro.get("db.user")); System.out.println(pro.get("db.password")); Class.forName(pro.getProperty("db.driver")); //加载链接 Connection conn = DriverManager.getConnection(pro.getProperty("db.url"), pro.getProperty("db.user"), pro.getProperty("db.password")); System.out.println(conn); } catch (Exception e) { e.printStackTrace(); } }