![](/img/trans.png)
[英]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.