Scala 读取配置文件
mysql.properties
mysql.url:jdbc:mysql://localhost:3306/testdb mysql.username:root mysql.password:sa123ADMIN
def main(args: Array[String]): Unit = { val file = this.getClass.getResourceAsStream("/mysql.properties") val properties = new Properties() properties.load(file) println(properties) println("----------") println(properties.getProperty("mysql.username")) //读取Key键的值 println(properties.getProperty("mysql.password", "*******")) if (file != null) { file.close() } }
{mysql.password=sa123ADMIN, mysql.url=jdbc:mysql://localhost:3306/testdb, mysql.username=root}
----------
root
sa123ADMIN


浙公网安备 33010602011771号