hivefans

readconfig.scala

Jun 4th, 2020
1,171
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Properties
  2. import java.io.FileInputStream
  3.  
  4. //test.properties 里的内容为"ddd=5.6,1.2"
  5.  
  6.   def loadProperties():Unit = {
  7.     val properties = new Properties()
  8.     val path = Thread.currentThread().getContextClassLoader.getResource("test.properties").getPath //文件要放到resource文件夹下
  9.     properties.load(new FileInputStream(path))
  10.     println(properties.getProperty("ddd"))//读取键为ddd的数据的值
  11.     println(properties.getProperty("ddd","没有值"))//如果ddd不存在,则返回第二个参数
  12.     properties.setProperty("ddd","123")//添加或修改属性值
  13.   }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×