• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Save properties

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic