[英]How to set null object in properties file groovy?
I am trying to set a object value to null in properties file but it is always being returned as string. 我试图在属性文件中将对象值设置为null,但始终以字符串形式返回。 Here is the sample code along with the properties file.
这是示例代码以及属性文件。
File propertiesFile = new File('/opt/config.properties')
propertiesFile.withInputStream {
properties.load(it)
}
**config.properties**
spotConfig = null
println properties.spotConfig
But when I am trying to print the above value, it is always returning string whereas I want it to print a null object. 但是,当我尝试打印上述值时,它总是返回字符串,而我希望它打印一个空对象。 How can I do that in groovy?
我如何才能做到这一点? Any help appreciated!
任何帮助表示赞赏!
Properties
keys and values are strings. Properties
键和值是字符串。 So you can't get a null
as value from a Properties
instance containing that key. 因此,您不能从包含该键的
Properties
实例中获得null
作为值。
In both of these cases, the value will be returned as a string: 在这两种情况下,该值都将作为字符串返回:
x=
y=null
properties.get("x")
will return ""
, and properties.get("y")
will return "null"
(the literal string). properties.get("x")
将返回""
, properties.get("y")
将返回"null"
(文字字符串)。
What you have to do is propbably remove the key from the file altogether (don't add a spotConfig
key in the file) to get null
您所要做的可能是从文件中完全删除密钥 (不要在文件中添加
spotConfig
密钥)以获取null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.