How to use Java property files?

后端 未结 17 1374
时光取名叫无心
时光取名叫无心 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条回答
  •  自闭症患者
    2020-11-22 11:48

    This load the properties file:

    Properties prop = new Properties();
    InputStream stream = ...; //the stream to the file
    try {
      prop.load(stream);
    } finally {
      stream.close();
    }
    

    I use to put the .properties file in a directory where I have all the configuration files, I do not put it together with the class that accesses it, but there are no restrictions here.

    For the name... I use .properties for verbosity sake, I don't think you should name it .properties if you don't want.

提交回复
热议问题