Java - Properties: Add new keys to properties file in run time?

前端 未结 1 1926
情深已故
情深已故 2020-12-11 03:38

Is it possible to create a new properties file and add keys and values in run time? I want to add new keys to properties file depending on user input while installing my app

相关标签:
1条回答
  • You can add new properties just by calling setProperty with a key which doesn't currently exist. That will only do it in memory though - you'll have to call store again to reflect the changes back to a file:

    Properties prop = new Properties();
    prop.load(...); // FileInputStream or whatever
    
    prop.setProperty("newKey", "newValue");
    prop.store(...); // FileOutputStream or whatever
    
    0 讨论(0)
提交回复
热议问题