spark 读取resources 配置文

xiaoxiao2021-02-28  67

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 () } }

转载请注明原文地址: https://www.6miu.com/read-82059.html

最新回复(0)