0

我有一个 Groovy 脚本来复制一个工作正常的文件,直到我尝试添加复制文件属性的选项,即保留​​时间戳。

这有效:

import java.nio.file.*

def fileEx = new File(/Y:\Documents\Test File.txt/)
def fileDest = new File(/Y:\Documents\Test File copied with Groovy and Nio.txt/)

def fileExPath = fileEx.toPath()
def fileDestPath = fileDest.toPath()

Files.copy(fileExPath, fileDestPath)

但这失败了:

import java.nio.file.*

def fileEx = new File(/Y:\Documents\Test File.txt/)
def fileDest = new File(/Y:\Documents\Test File copied with Groovy and Nio.txt/)

def fileExPath = fileEx.toPath()
def fileDestPath = fileDest.toPath()

Files.copy(fileExPath, fileDestPath, COPY_ATTRIBUTES)

出现错误:

Caught: groovy.lang.MissingPropertyException: No such property: COPY_ATTRIBUTES for class: temp
groovy.lang.MissingPropertyException: No such property: COPY_ATTRIBUTES for class: temp
    at temp.run(temp.groovy:9)

我尝试将 COPY_ATTRIBUTES 放在单引号和双引号中,但这没有帮助。请有人能告诉我我做错了什么吗?

4

1 回答 1

4

您需要参考枚举类:

Files.copy(fileExPath, fileDestPath, StandardCopyOption.COPY_ATTRIBUTES)
于 2012-11-05T13:30:44.353 回答