import java.io.FileReader val configFile = new java.io.File("/tmp/sample.properties") val reader = new FileReader(configFile) val props = new Properties() props.load(reader) reader.close()
import com.typesafe.config.ConfigFactory val configFile = new java.io.File("/tmp/sample.properties") val kafkaConfig = ConfigFactory.parseFile(configFile)
import java.util.Properties val kafkaProperties = new Properties() kafkaProperties.put("zookeeper.hosts", kafkaConfig.getString("kafka.zkhost")) kafkaProperties.put("zookeeper.port", kafkaConfig.getInt("kafka.zkports"):java.lang.Integer) kafkaProperties.put("kafka.topic", kafkaConfig.getString("kafka.topic"))
1条答案
按热度按时间yr9zkbsy1#
给这个属性文件
/tmp/sample.properties
```kafka.topic = "mytopic"
kafka.zkhost = "localhost"
kafka.zkports = 2191
import java.io.FileReader
val configFile = new java.io.File("/tmp/sample.properties")
val reader = new FileReader(configFile)
val props = new Properties()
props.load(reader)
reader.close()
import com.typesafe.config.ConfigFactory
val configFile = new java.io.File("/tmp/sample.properties")
val kafkaConfig = ConfigFactory.parseFile(configFile)
import java.util.Properties
val kafkaProperties = new Properties()
kafkaProperties.put("zookeeper.hosts", kafkaConfig.getString("kafka.zkhost"))
kafkaProperties.put("zookeeper.port", kafkaConfig.getInt("kafka.zkports"):java.lang.Integer)
kafkaProperties.put("kafka.topic", kafkaConfig.getString("kafka.topic"))