I need my Java app to read the config properties from a file and use them throughout the classes. I’m thinking of a separate class, that would return a map of property_key:property_value for each of the properties in the file. Then I would read the values from this map in other classes.
Maybe there are other, more commonly used options?
My properties file is simple and has about 15 entries.
Just use
java.util.Propertiesto load it. It implementsMapalready.You can load and get hold of the properties statically. Here’s an example assuming that you’ve a
config.propertiesfile in thecom.examplepackage:Which can be used as
You could if necessary abstract this implementation away by an interface and get the instance by an abstract factory.