hivefans icon

readconfig.scala

hivefans | PRO | 06/04/20 07:10:03 AM UTC | 0 ⭐ | 9235 👁️ | Never ⏰ | []
Scala |

600 B

|

None

|

0 👍

/

0 👎

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")//添加或修改属性值
  }

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎