How to use Java property files?

后端 未结 17 1391
时光取名叫无心
时光取名叫无心 2020-11-22 11:13

I have a list of key/value pairs of configuration values I want to store as Java property files, and later load and iterate through.

Questions:

  • Do I ne
17条回答
  •  旧时难觅i
    2020-11-22 11:34

    If you put the properties file in the same package as class Foo, you can easily load it with

    new Properties().load(Foo.class.getResourceAsStream("file.properties"))
    

    Given that Properties extends Hashtable you can iterate over the values in the same manner as you would in a Hashtable.

    If you use the *.properties extension you can get editor support, e.g. Eclipse has a properties file editor.

提交回复
热议问题