scala学习-12-scala读取java项目下Src目录下的properties文件

来源:互联网 发布:mysql 执行两条语句 编辑:程序博客网 时间:2024/05/18 22:43

scala读取java项目下Src目录下的properties文件
这里写图片描述

package scalaimport java.util.Propertiesimport java.io.FileInputStreamimport scala.tools.scalap.Mainobject PropertiesScalaUtils {  def loadProperties(key:String):Unit = {    val properties = new Properties()    val in = PropertiesScalaUtils.getClass.getClassLoader.getResourceAsStream("config_scala.properties")    //val path = Thread.currentThread().getContextClassLoader.getResource("config_scala.properties").getPath //文件要放到resource文件夹下    properties.load(in);     println(properties.getProperty(key))//读取键为ddd的数据的值  }}
原创粉丝点击