Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save values to properties without deleting unmodified keys?

So if we do like this:

 Properties props = new Properties();
 OutputStream osr = new FileOutputStream(Store.class.getResource("my.properties").getFile());

 props.setProperty("wallboard_text_rgb", "aaa");
 props.setProperty("wallboard_back_rgb", "bbb");

 props.store(osr, "");

other keys in existing properties will be deleted, how to avoid that?

like image 403
VextoR Avatar asked Feb 17 '12 10:02

VextoR


People also ask

Which keyword is used for deleting properties?

delete keyword is used to delete properties of an object in javaScript.

How do you add properties to an object?

One way is to add a property using the dot notation: obj. foo = 1; We added the foo property to the obj object above with value 1.

What are the possible ways of deleting a property from an object?

There are two ways to remove a property from a JavaScript object. There's the mutable way of doing it using the delete operator, and the immutable way of doing it using object restructuring.


1 Answers

Load properties from that file before modifying it. In other words, replace

Properties props = new Properties();

with

Properties props = Properties.load(new FileInputStream(Store.class.getResource("my.properties").getFile())); 
like image 170
Mersenne Avatar answered Sep 23 '22 06:09

Mersenne