Scala: load Java properties

java, properties, scala

Solution

Mostly the same (if you're not using any config library):

val (host, port, dbName, docsCollName) = 
  try {
    val prop = new Properties()
    prop.load(new FileInputStream("config.properties"))

    (
      prop.getProperty("mongo.host"),
      new Integer(prop.getProperty("mongo.port")),
      prop.getProperty("mongo.db"),
      prop.getProperty("mongo.coll.docs")
    ) 
    } catch { case e: Exception => 
      e.printStackTrace()
      sys.exit(1)
    }

Problem

What would be easy to read and understand, Scala code to load Java properties according to the following Java code: ``` try { Properties prop = new Properties(); prop.load(new FileInputStream("config.properties")); this.host = prop.getProperty("mongo.host"); this.port = new Integer(prop.getProperty("mongo.port")); this.dbName = prop.getProperty("mongo.db"); this.docsCollName = prop.getProperty("mongo.coll.docs"); } catch (Exception e) { e.printStackTrace(); System.exit(1); } ``` Thanks!

Original source

Related problems