2012-10-18 28 views
1

我已经在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) 

回答

1

尝试new File(sourceDir).eachFileMatch(regex, fileCopyClosure)

+0

一个File只要你指出来,这似乎很明显。感谢第二双眼睛。 – chopland

0

从异常,sourceDir是一个字符串,而不是你需要eachFileRecurse