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