我正在尝试使用以下代码将多个文件从一个文件夹复制到另一个文件夹
val pathCorpus = Files.copy(
Paths.get("src/main/resources/corpusDirectory/corpus.mallet"),
Paths.get("src/main/resources/corpus.mallet"),
StandardCopyOption.REPLACE_EXISTING
)
val pathInferencer = Files.copy(
Paths.get("src/main/resources/corpusDirectory/inferencer"),
Paths.get("src/main/resources/inferencer"),
StandardCopyOption.REPLACE_EXISTING
)
因为我需要复制两个文件,所以我使用了两次Files.copy
。代码正在工作,但我相信应该有更好的方法来编写代码,比如递归复制文件。
发布于 2019-05-31 02:39:19
better-files
支持通过source.copyTo(destination)
语法递归复制目录。下面是一个有效的示例
import better.files._
object Hello extends App {
val source = file"/your/sourceDir"
val destination = file"/your/destinationDir"
source.copyTo(destination)
}
其中我们需要以下依赖项
libraryDependencies += "com.github.pathikrit" %% "better-files" % "3.8.0"
https://stackoverflow.com/questions/56381165
复制相似问题