scalatypesafe-confighocon

Scala: Write value to typesafe config object


I'm using Typesafe config & have a config file in my resources directory which looks like this:

something {
  another {
    someconfig=abc
    anotherconfig=123
  }
}

How would I change the value of anotherconfig using scala?


Solution

  • If you want to change the loaded config (i.e. create a new config based on the old one), you can use withValue:

    val newConfig = oldConfig.withValue("something.another.anotherconfig",
      ConfigValueFactory.fromAnyRef(456))