为什么 getProperty() 返回 null?
我有一段定义属性的代码,如下所示:
public static final String DEFINED_KEY = "definedKey";
public static final String DEFINED_PROPERTY = "definedProperty";
// [...]
File f = File.createTempFile("default", ".properties");
PrintWriter pw = new PrintWriter(f);
Properties pp = new Properties();
pp.setProperty(DEFINED_KEY, DEFINED_PROPERTY);
pp.store(pw, "Automatically defined");
pw.close();
它保存属性文件 OK
#No comments
#Mon Feb 13 17:25:12 CET 2012
definedKey=definedProperty
当我创建另一个属性并对其执行 load()
时,它加载正常。 get(DEFINED_KEY)
返回为 DEFINED_PROPERTY
指定的值,但 getProperty(DEFINED_KEY)
返回 null
。这是怎么回事?
I have a piece of code defining a property like this:
public static final String DEFINED_KEY = "definedKey";
public static final String DEFINED_PROPERTY = "definedProperty";
// [...]
File f = File.createTempFile("default", ".properties");
PrintWriter pw = new PrintWriter(f);
Properties pp = new Properties();
pp.setProperty(DEFINED_KEY, DEFINED_PROPERTY);
pp.store(pw, "Automatically defined");
pw.close();
Which saves a properties file OK
#No comments
#Mon Feb 13 17:25:12 CET 2012
definedKey=definedProperty
When I create another property and perform a load()
on it, it loads OK. get(DEFINED_KEY)
returns the value specified for DEFINED_PROPERTY
, but getProperty(DEFINED_KEY)
returns null
. What's up with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有发现您的代码有任何问题...这是我的测试:-
生成的输出:-
I don't see anything wrong with your code... here's my test:-
The generated output:-