gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 14:17:19 24 4
gpt4 key购买 nike

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

public static Path createSymbolicLink(Path link,                      Path target,                      FileAttribute... attrs)                               throws IOExceptionCreates 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 createtarget - the target of the symbolic linkattrs - 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com