当我使用sbt.IO.copyFile
或sbt.IO.copyDirectory
复制文件或文件夹时,文件上的可执行标记将被丢弃。使用sbt帮助函数有没有办法解决这个问题,还是必须使用基本的Java复制函数?
答案 0 :(得分:1)
使用:
java.nio.file.Files.copy(Path source, Path target, CopyOption... options)
例如,如果您在当前目录中有fromdos:
scala> import java.nio.file._
import java.nio.file._
scala> Files.copy(Paths.get("fromdos"),Paths.get("copyFromDos"),StandardCopyOption.COPY_ATTRIBUTES)
res0: java.nio.file.Path = copyFromDos
复制目录
def copyDir(source: Path, dest: Path) {
Files.copy(source, dest, StandardCopyOption.COPY_ATTRIBUTES)
if (source.toFile.isDirectory) {
val dir = source.toFile
dir.listFiles.foreach(file =>
copyDir(file.toPath, dest.resolve(file.getName)))
}
}