I have two java programs. The first is authorized by the seller and creates a product in the store. The second is authorized by the buyer and buys it.

He is interested in how correctly in the first program to write / rewrite a parameter in the config.properties order to read it in the second.

I can only write the config with my hands and read parameters from it, or create a dynamic one, but it lives while the program is running, and I need to read the parameter when executing another program.

Please do not suggest me to change the architecture of the application.

    1 answer 1

    Sharing information using properties files is not a good idea. In most cases, they should be strictly read-only .
    For your case, the database is more suitable, for example, h2 . But if you want so, you can create a file, for example:

     Path path = Paths.get("config.xml") Properties properties = new Properties(); properties.setProperty("key", "value"); properties.storeToXML(Files.newOutputStream(path),"this is very important file"); 

    And read the parameters like this:

     Properties properties = new Properties(); properties.loadFromXML(Files.newInputStream(path)); System.out.println(properties.getProperty("key")); 

    value

    PS if the store and load methods are used appropriately, then the file will have the file properties structure, not xml as in the example.