以下是易于阅读和理解的 Scala 代码,用于加载 Java 属性。与以下 Java 代码相对应:
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);
}
谢谢!