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!
I will certainly recommend the typesafe config, written by the company behind Scala and used at least by Akka framework.
Features (quoted from wiki):
Example:
Config conf = ConfigFactory.load();
int bar1 = conf.getInt("foo.bar");
Config foo = conf.getConfig("foo");
int bar2 = foo.getInt("bar");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With