Delete key and value from a property file?

前端 未结 2 681
[愿得一人]
[愿得一人] 2021-01-17 07:41

I want to delete key and value which is stored in a property file. How can i do that????

2条回答
  •  猫巷女王i
    2021-01-17 08:22

    First load() it using the java.util.Properties API.

    Properties properties = new Properties();
    properties.load(reader);
    

    Then you can use the remove() method.

    properties.remove(key);
    

    And finally store() it to the file.

    properties.store(writer, null);
    

    See also:

    • Properties tutorial

提交回复
热议问题