Best way to get values from a external file in java -


i have java code i'm running jar. code checks specific file in given directory hard coded in code.

to give more flexibility , not touch code. have folers list managed different file , code reads config file , gets list of folders each time , execute it.

i know best possible option of maintaining folder list outside code can update it. can properties used ? can dynamically take values property file

in java have java.util.properties allow load flat key/value data external resources.

if need can dynamically updated, there's more sophisticated preferences library. 1 allows to:

  1. keep data organized in tree structures (it's tree of nodes, each node storing own key/value preferences).
  2. make use of basic types (primitive types, strings , binary data).
  3. make use of platform-dependent "native" stores transparently (under hood, it's going use file system on unix systems , registries on windows default).
  4. plug in own backing store if needed.
  5. get data changes performed within application persisted transparently.
  6. register node/preference change listeners , react change if needed.

the api quite old , hasn't been updated, doesn't mean it's deprecated. used gui applications (notably, intellij idea storing configuration using preferences last time checked).

there's attempt revive library made project called cross-preferences integrating modern distributed config stores (such zookeeper, etcd or consul) backing stores java.util.prefs.preferences , providing web console preference management.


Comments