如何使用Groovy从属性文件中获取值?
我需要一个属性文件(.properties),它将文件名作为键,并将其目标路径作为值.我需要在运行时解析密钥,具体取决于需要移动的文件.
到目前为止,我能够加载它看起来的属性,但不能从加载的属性"获取"值.
我提到了线程:groovy:如何访问属性文件?以下是我到目前为止的代码片段
def props = new Properties();
File propFile =
new File('D:/XX/XX_Batch/XX_BATCH_COMMON/src/main/resources/patchFiles.properties')
props.load(propFile.newDataInputStream())
def config = new ConfigSlurper().parse(props)
def ant = new AntBuilder()
def list = ant.fileScanner {
fileset(dir:getSrcPath()) {
include(name:"**/*")
}
}
for (f in list) {
def key = f.name
println(props)
println(config[key])
println(config)
def destn = new File(config['a'])
}
Run Code Online (Sandbox Code Playgroud)
属性文件现在具有以下条目:
jan-feb-mar.jsp=/XX/Test/1
XX-1.0.0-SNAPSHOT.jar=/XX/Test/1
a=b
c=d
Run Code Online (Sandbox Code Playgroud)
如果我使用props.getProperty('a')或config ['a']查找,则返回正确的值.还尝试了代码:notation
但是一旦切换到使用变量"key",就像在config [key]中一样,它返回 - > [:]
我是groovy的新手,不能说我在这里失踪了什么.