Lahniep
Lahniep

Reputation: 729

Java - Add a new entry pair to Properties file in Runtime

I want to add a new NewKey-NewValue pair to my config properties file in runtime. I tried :

Properties p = new Properties();
p.load(fileinpustream ...);
...
p.setProperty("NewKey","NewValue");
p.store(outputstream, "comment");

But i always get a NullPointerException on the setProperty line. Any suggestion?

Thanks.

Upvotes: 0

Views: 638

Answers (1)

alexdolgin
alexdolgin

Reputation: 66

Make sure your "NewValue" isn't null

This is from Hashtable, parent of java.util.Properties

...

public synchronized V put(K key, V value) {
// Make sure the value is not null
if (value == null) {
    throw new NullPointerException();
}

...

Upvotes: 5

Related Questions