一、大数据中的配置文件:properties文件,通常放在项目工程的resources目录中
package com.learning.bigdata.bigdata
import java.io.InputStream
import java.util.Properties
import org.apache.commons.lang3.StringUtils
object properties {
def main(args: Array[String]): Unit = {
//Properties经常用的方法:put load getProperty/get
val prop: Properties = new Properties()
//1、通过加载外面资源文件,然后用properties去取
val in: InputStream = this.getClass.getClassLoader().getResourceAsStream("db.properties") //将外部资源文件以流的方式来加载
if(in != null){
prop.load(in)
System.err.println(s"加载的数据库的用户名:${prop.getProperty("user")},密码:${prop.getProperty("password","123456")}")
}
//2、这种直接把内容放到properties里面去,然后去取
prop.put("user","admin")
prop.put("password","199226")
println(prop.get("user"))
}
}
二、配置文件:properties文件还可以通过提交Spark时,spark-submit的时候提交这个properties文件提交的时候用:
–driver-class-path “
b
i
n
d
i
r
/
e
t
l
.
p
r
o
p
e
r
t
i
e
s
:
bindir/etl.properties:
bindir/etl.properties:bindir/jars/mysql-connector-java-5.1.8.jar” \