首先将配置文件db.properties 放在Resources文件夹下
直接上读取文件源码
//第一种方法
ResourceBundle rb = ResourceBundle.getBundle("db");
url = rb.getString("url");
Driver = rb.getString("Driver");
username = rb.getString("username");
password =rb.getString("password");
//SimpleDBSource为当前类的名称
//第二种方法
Properties p = new Properties();
p.load(SimpleDBSource.class.getClassLoader().getResourceAsStream("db.properties"));
url = p.getProperty("url");
Driver = p.getProperty("Driver");
username = p.getProperty("username");
password = p.getProperty("password");
} catch (Exception e) {
e.printStackTrace();
}
}
这样就能读取到文件了。