application.conf和application.properties的區別

.conf  需要加 “”

.properties  不需要“”

import java.util.Properties
import java.io.FileInputStream

//test.properties 裏的內容爲"ddd=5.6,1.2"

  def loadProperties():Unit = {
    val properties = new Properties()
    val path = Thread.currentThread().getContextClassLoader.getResource("test.properties").getPath //文件要放到resource文件夾下
    properties.load(new FileInputStream(path))
    println(properties.getProperty("ddd"))//讀取鍵爲ddd的數據的值
    println(properties.getProperty("ddd","沒有值"))//如果ddd不存在,則返回第二個參數
    properties.setProperty("ddd","123")//添加或修改屬性值
  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章