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

 

 

 

posted @ 2021-03-21 22:22  茗::流  阅读(0)  评论(0)    收藏  举报
如有雷同,纯属参考。如有侵犯你的版权,请联系我。