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

标签 java interface java-7 symlink file-attributes

我想使用 Java 在 RHEL 5 中创建符号链接(symbolic link)。在java6中createSymbolicLink只有两个参数。但在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

我不明白我应该给出什么作为第三个参数。我需要做的就是创建一个符号链接(symbolic link)。

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

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

最佳答案

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

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

关于java - RHEL 5 中带有 Files.createSymbolicLink (Java 7) 的符号链接(symbolic link),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18009545/

相关文章:

java - 如何在 Java 中计时方法的执行?

java 使用 JOptionpane 重置计数器并关闭程序

java - 调用递归函数如何改变结果?

java - 私有(private)接口(interface)方法,示例用例?

linux - 安装Sun JDK 7时事务检查错误

java - 在 Java 中声明一个大尺寸的 2d Double 数组

c# - 在非托管 cpp dll 中实现 C# 接口(interface)

java - 如何从多个类更新 GUI?

java - 如何在 Eclipse Swing 项目中使用 JavaFX

java - JDK1.6和JDK1.7拖拽区别