我想在运行时向配置属性文件中添加一个新的NewKey-NewValue对。我试过了:
Properties p = new Properties();
p.load(fileinpustream ...);
...
p.setProperty("NewKey","NewValue");
p.store(outputstream, "comment");
但是我总是在setProperty行上得到一个NullPointerException。 有什么建议吗?
感谢。
答案 0 :(得分:5)
确保您的“NewValue”不是 null
这是来自Hashtable,java.util.Properties的父级
...
public synchronized V put(K key, V value) {
// Make sure the value is not null
if (value == null) {
throw new NullPointerException();
}
...