我已经在Groovy脚本中编写了一个闭包来复制文件,然后将该闭包传递给eachFileMatch(regex,closure)以复制与给定正则表达式匹配的所有文件。当我在Groovy的控制台一切原型,它的工作就好了,但现在,当我在Eclipse中运行它,我得到以下错误:在Groovy中传递闭包到函数时出错
groovy.lang.MissingMethodException: No signature of method: java.lang.String.eachFileMatch() is applicable for argument types: (java.util.regex.Pattern, file_copy$_run_closure3)
这里是封闭和调用eachFileMatch()
def fileCopyClosure = {
if(it.canRead()){
def destFolder = new File("${outputDirectory}")
if(!destFolder.exists()){
println "Creating directory"
destFolder.mkdir()
}
def desti = new File("${outputDirectory}\\${it.name}")
output = desti.newOutputStream()
it.eachByte(1024, write)
output.close()
}
}
sourceDir.eachFileMatch(regex, fileCopyClosure)
一个
File
只要你指出来,这似乎很明显。感谢第二双眼睛。 – chopland