application.properties的内容如下:
测试数据库连接信息
test.db.url=jdbc:mysql://localhost:3308/xxxx
test.db.username=xxxxxxxxxx
test.db.password=xxxxxxxxxx
线上数据库连接信息
online.db.url=jdbc:mysql://localhost:3308/xxxx
online.db.username=xxxxxxxxxxxx
online.db.password=xxxxxxxxxxxx
当需要使用Java程序读取application.properties配置文件的内容并按照key-value形式读取时,代码如下:
Properties properties = new Properties();
//当前类
InputStream inputStream = CompareDB.class.getResourceAsStream("/application.properties");
properties.load(inputStream);
String url = properties.getProperty("test.db.url");
String username = properties.getProperty("test.db.username");
String password = properties.getProperty("test.db.password");



