-
Notifications
You must be signed in to change notification settings - Fork 0
Properties Files
Philip Ford edited this page Jan 6, 2017
·
2 revisions
-
Get the file with
new File("file path"). -
Then call
withInputStream (closure)on the File object.propertiesFile.withInputStream { properties.load(it) // "properties" is a Properties object created above. }
-
Within the
withInputStreamclosure, callload(it)on the properties instance, as shown in the previous example, and in the example below.- "it" is the default closure parameter in Groovy, so it represents the prperties read from the InputStream and is being passed to
properties.load().
- "it" is the default closure parameter in Groovy, so it represents the prperties read from the InputStream and is being passed to
For given test.properties file:
a=1
b=2Properties properties = new Properties()
File propertiesFile = new File('test.properties')
propertiesFile.withInputStream {
properties.load(it)
}
// testing...
def runtimeString = 'a'
assert properties."$runtimeString" == '1'
assert properties.b == '2'