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 =>
      println(line)
      val tokens = line.split("=")
      ( tokens(0) -> tokens(1))
    }.toMap
  }
Once you have this method you can call it like this getConfig(filePath)

3 comments:

  1. 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.

    ReplyDelete
  2. is possible to read property file in pyspark, that is my requirement, can u please help me any one

    ReplyDelete