繁体   English   中英

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

[英]Symlink with Files.createSymbolicLink (Java 7) in RHEL 5

我想使用Java在RHEL 5中创建符号链接。 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

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

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

对于下降投票者,请评论下降投票的原因。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM