[英]Error passing closure to function in Groovy
我已经在Groovy脚本中编写了一个闭包来复制文件,然后将该闭包传递给eachFileMatch(regex,closure)以复制与给定regex匹配的所有文件。 当我在Groovy Console中对它进行原型设计时,一切工作都很好,但是现在当我在Eclipse中运行它时,出现以下错误:
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)
尝试new File(sourceDir).eachFileMatch(regex, fileCopyClosure)
从异常, sourceDir
是一个字符串,而不是一个File
,你需要eachFileRecurse
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.