Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Save properties

 
ivy liao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If I read a properties file using following way, after that, I want to add some key/value to that file, how can I do?
InputStream in = ClassLoader.getSystemResourceAsStream("com/company/testing.properties");
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a Singleton wrapper for the properties object and have it running on a thread so that it periodically (really low priority) checks the source file and reloads if the file has changed.
Dave.
 
ivy liao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry that I did not describe my question very clearly.
I want to find a way for appending some key/value to the properties file because I will add some key/value after I load the properties. My source code are as following:
InputStream in = ClassLoader.getSystemResourceAsStream("com/company/testing.properties");
Properties p = new Properties;
p.load(in);
p.put("testing", "newValue");
----
After above code, I want to save the new key and value to the file, How to do it?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to save the modified Properties back to the file?
Never used it, but according to the API shouldn't store(OutputStream out, String header) do it?
Or am I missing out on the picture again?
Dave.
 
ivy liao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means I can not modify the properties to that file?
If I use 'store' API, I don't know how to convert my properties 'com/company/testing.properties' as a OutputStream?
 
Tim Holloway
Bartender
Posts: 18419
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't really the forum you want to ask that question in - properties are part of the basic Java system. However, the normal use would be to load properties, use them, add/update properties, then save them. You'd normally create an OutputStream on the same file you loaded from to write the updated properties on.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!