[英]how to define and access array in grails from config.groovy file
[英]How to set null object in properties file groovy?
我试图在属性文件中将对象值设置为null,但始终以字符串形式返回。 这是示例代码以及属性文件。
File propertiesFile = new File('/opt/config.properties')
propertiesFile.withInputStream {
properties.load(it)
}
**config.properties**
spotConfig = null
println properties.spotConfig
但是,当我尝试打印上述值时,它总是返回字符串,而我希望它打印一个空对象。 我如何才能做到这一点? 任何帮助表示赞赏!
Properties
键和值是字符串。 因此,您不能从包含该键的Properties
实例中获得null
作为值。
在这两种情况下,该值都将作为字符串返回:
x=
y=null
properties.get("x")
将返回""
, properties.get("y")
将返回"null"
(文字字符串)。
您所要做的可能是从文件中完全删除密钥 (不要在文件中添加spotConfig
密钥)以获取null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.