我真的坚持这个错误。这对我没有任何意义。为什么参数类型UnixPath, null
?我试图按预期打印tempDir
变量 - e.i.具有正确路径的路径对象。
有什么想法吗?
没有方法签名:build_76p6jmah0vklon2l29au5dqlcr $ _copyRecursively_closure3.doCall()适用于参数类型:(sun.nio.fs.UnixPath,null)值:[generic / bundle,...] 可能的解决方案:doCall(),doCall(java.lang.Object),findAll(),findAll()
readFile(args[Property.CONFIG_FILE.propertyName]).eachLine {
if (new File(it).isDirectory()) {
copyRecursively(Paths.get(it), tempDir)
} else {
println "File $it is not a directory. Skipping."
}
}
void copyRecursively(Path sourceDir, Path destinationDir) {
Files.walkFileTree(sourceDir, [FileVisitOption.FOLLOW_LINKS] as Set, Integer.MAX_VALUE, [
postVisitDirectory: { return FileVisitResult.CONTINUE },
preVisitDirectory: {filePath, attrs ->
Path newDirectory = destinationDir.resolve(sourceDir.relativize(filePath));
Files.copy(filePath, newDirectory, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING)
return FileVisitResult.CONTINUE;
},
visitFile: { filePath, attrs ->
Files.copy(filePath, destinationDir.resolve(sourceDir.relativize(filePath)), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
},
visitFileFailed: { return FileVisitResult.CONTINUE }
] as java.nio.file.FileVisitor)
}
答案 0 :(得分:1)
您面临的问题是因为FileVisitor
对象没有正确构造bean。方法visitFileFailed
& postVisitDirectory
期望两个参数,但您没有提供任何参数。解决问题后,copyRecursively
的正确方法定义为:
void copyRecursively(Path sourceDir, Path destinationDir) {
FileVisitor visitor =[
preVisitDirectory : { Path filePath, BasicFileAttributes attrs ->
Path newDirectory = destinationDir.resolve(sourceDir.relativize(filePath))
Files.copy(filePath, newDirectory, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING)
return FileVisitResult.CONTINUE
},
visitFile : { Path filePath, BasicFileAttributes attrs ->
Files.copy(filePath, destinationDir.resolve(sourceDir.relativize(filePath)), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING)
return FileVisitResult.CONTINUE
},
visitFileFailed : { file, IOException ex -> return FileVisitResult.CONTINUE },
postVisitDirectory: { dir, IOException ex -> return FileVisitResult.CONTINUE }
] as FileVisitor
Files.walkFileTree(sourceDir, [FileVisitOption.FOLLOW_LINKS] as Set, Integer.MAX_VALUE, visitor)
}