【Scala】读写Propertie后缀的配置文件
作者:互联网
PropertiesUtil.scala
import java.io.InputStreamReader
import java.util.Properties
/**
* @author Uni
* @create 2021/12/2 12:37
* 读取 properties 配置文件的工具类
*/
object PropertiesUtil {
def main(args: Array[String]): Unit = {
val properties : Properties = PropertiesUtil.load("config.properties")
println(properties.getProperty("kafka.broker.list"))
}
def load(propertieName: String): Properties = {
val prop = new Properties()
prop.load(new InputStreamReader(Thread.currentThread().
getContextClassLoader.
getResourceAsStream(propertieName),
"UTF-8"))
prop
}
}
测试文本
config.properties
# Kafka 配置
kafka.broker.list=hadoop101:9092,hadoop102:9092,hadoop103:9092
输出结果
hadoop101:9092,hadoop102:9092,hadoop103:9092
标签:load,Propertie,配置文件,Scala,PropertiesUtil,9092,properties,prop,Properties 来源: https://www.cnblogs.com/unirithe/p/15632707.html