0

I have a config.properties file in a jar and I would like to read and write in this file , to read I used

def config = CodeGenerator.getResourceAsStream("/config.properties")
Properties props = new Properties()
props.load(config)
def patternId = props.patternId as Integer;
def groupId = props.patternGroupId as Integer;
...
props.store(???)

but I don't know how to write my properties values ​​in this file ?

Belgacem
  • 183
  • 9
  • You can **read** it from a jar file. Writing to a jar is the same as writing to a zip file. And then you'd have to write your own class-loader to reload the jar after you write to it. I would not do that. Instead **read** it, and if you need to update a setting write that to an external config file in the user's home folder. Now you only have to track two files (or you write everything to that external config file and check which file to use based on its' existence). Basically, Mick Jagger said it best: *You can't always get what you want*. – Elliott Frisch Apr 13 '20 at 13:59
  • Do you really need to store data into the property file to save them or do you simply need to keep those properties into memory at runtime? check this answer too: https://stackoverflow.com/questions/22370051/how-to-write-values-in-a-properties-file-through-java-code – Alex C. Apr 13 '20 at 16:44

0 Answers0