RHEL 5中带有Files.createSymbolicLink(Java 7)的符号链接

RHEL 5中带有Files.createSymbolicLink(Java 7)的符号链接,java,interface,java-7,symlink,file-attributes,Java,Interface,Java 7,Symlink,File Attributes,我想使用Java在RHEL 5中创建一个符号链接。在java6中,只有两个参数。但在Java7的情况下,FileAttribute与参数一起包含,即总共三个参数 public static Path createSymbolicLink(Path link, Path target, FileAttribute... attrs) throws I

我想使用Java在RHEL 5中创建一个符号链接。在java6中,只有两个参数。但在Java7的情况下,FileAttribute与参数一起包含,即总共三个参数

public static Path createSymbolicLink(Path link, Path target, FileAttribute... attrs) throws IOException Creates a symbolic link to a target (optional operation). The target parameter is the target of the link. It may be an absolute or relative path and may not exist. When the target is a relative path then file system operations on the resulting link are relative to the path of the link. The attrs parameter is optional attributes to set atomically when creating the link. Each attribute is identified by its name. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored. Where symbolic links are supported, but the underlying FileStore does not support symbolic links, then this may fail with an IOException. Additionally, some operating systems may require that the Java virtual machine be started with implementation specific privileges to create symbolic links, in which case this method may throw IOException. Parameters: link - the path of the symbolic link to create target - the target of the symbolic link attrs - the array of attributes to set atomically when creating the symbolic link 公共静态路径链接(路径链接, 路径目标, 文件属性…属性) 抛出IOException 创建指向目标的符号链接(可选操作)。 目标参数是链接的目标。它可能是绝对路径或相对路径,并且可能不存在。当目标是相对路径时,结果链接上的文件系统操作是相对于链接的路径的。 attrs参数是在创建链接时以原子方式设置的可选属性。每个属性都由其名称标识。如果数组中包含多个同名属性,则将忽略除最后一次出现以外的所有属性。 如果支持符号链接,但底层文件存储不支持符号链接,则可能会因IOException而失败。此外,一些操作系统可能要求Java虚拟机以特定于实现的权限启动,以创建符号链接,在这种情况下,此方法可能引发IOException。 参数: 链接-要创建的符号链接的路径 target-符号链接的目标 attrs-创建符号链接时原子设置的属性数组 我不明白我应该给出什么作为第三个参数。我所需要做的就是创造一个象征性的叮当声

问题是我不知道应该在第三个参数中给出什么,而且我对
FileAttribute
接口也不太了解。请帮忙


对于向下投票人,请评论向下投票的原因。

源和目标是路径而不是文件名。 将代码更改为:

Files.createSymbolicLink(Paths.get(sourceFileName), Paths.get(targetFileName));

第三个属性呢?第三个属性是可选的,仅在某些平台上有意义。检查上的文档。在Java6中,您将“file1”链接到“file2”,在Java7中,您将path.get(“file1”)链接到path.get(“file2”)。试试我给你举的例子。它起作用了。