How to use Java property files?

后端 未结 17 1386
时光取名叫无心
时光取名叫无心 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:36

    Reading a properties file and loading its contents to Properties

    String filename = "sample.properties";
    Properties properties = new Properties();
    
    input = this.getClass().getClassLoader().getResourceAsStream(filename);
    properties.load(input);
    

    The following is the efficient way to iterate over a Properties

        for (Entry entry : properties.entrySet()) {
    
            System.out.println(entry.getKey() + " => " + entry.getValue());
        }
    

提交回复
热议问题