Read configuration from .properties file in

This is small utility function in Scala, that takes fully qualified path of the properties file, and converts it into Map and returns. I use it for taking path of the properties file in my standalone Scala program and load it into Map

def getConfig(filePath: String)= {
    Source.fromFile(filePath).getLines().filter(line => line.contains("=")).map{ line =>
      val tokens = line.split("=")
      ( tokens(0) -> tokens(1))
Once you have this method you can call it like this getConfig(filePath)

1 comment:

Manikanth said...

Thanks for the post.
I want to get the filePath from arguments or from command line while submitting the jar. Can you help me how to achieve that.
Appreciate your help on this. Thanks in advance.