src/main/resources
第一步。首先配置maven的资源选项,比如
第二部:代码(src/main/resources/conf/area.properties)
package kafka.spark.streaming import java.io.{FileInputStream, InputStream} import java.net.URL import java.util.Properties /** * Created by on 2017/5/16. */ object Test extends Serializable{ def main(args: Array[String]): Unit = { val resource: URL = this.getClass.getClassLoader.getResource("conf/area.properties") val in:InputStream = new FileInputStream(resource.getPath) val props : Properties = new Properties props.load(in) //判断传入数据是否存在 def isExist(key: String): Boolean = { props.containsKey (key) } def getData(x:String ): String = { if(!isExist(x)){ return null } val property: String = props.getProperty (x) property } val property: String = getData("010") print(property) in.close () } }
