在RHEL 5中使用Files.createSymbolicLink(Java 7)进行符号链接 [英] Symlink with Files.createSymbolicLink (Java 7) in RHEL 5

查看:276
本文介绍了在RHEL 5中使用Files.createSymbolicLink(Java 7)进行符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Java在RHEL 5中创建符号链接.在java6中, createSymbolicLink 只有两个参数.但是在Java7的情况下,FileAttribute随参数一起被包括在内,即总共三个参数.

I want to create a symlink in RHEL 5 using Java. In java6 createSymbolicLink have only two parameters. But in case of Java7 FileAttribute has been included along with the parameters, ie a total of three parameters.

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

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

I couldn't understand what should I give there as third parameter. All I need to do is to create a symboliclink.

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

The problem is I don't know what I should give in third parameter, and also I am not having much idea about FileAttribute interface. Please help.

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

For Downvoters please comment reason for downvoting.

推荐答案

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

Source and target are paths not filenames. change your code to:

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

这篇关于在RHEL 5中使用Files.createSymbolicLink(Java 7)进行符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆