Симлинк с Files.createSymbolicLink (Java 7) в RHEL 5

Я хочу создать символическую ссылку в RHEL 5 с помощью Java. В 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. Пожалуйста помоги.

Для Downvoters, пожалуйста, прокомментируйте причину для downvoting.


person Maximin    schedule 02.08.2013    source источник


Ответы (1)


Источник и цель - это пути, а не имена файлов. измените свой код на:

Files.createSymbolicLink(Paths.get(sourceFileName), Paths.get(targetFileName));
person Paul Smith    schedule 23.10.2013
comment
Что насчет третьего атрибута? - person Maximin; 25.10.2013
comment
Третий атрибут является необязательным и имеет смысл только на определенных платформах. Ознакомьтесь с документацией по Oracle. В Java 6 вы связываете файл1 с файлом2, в Java 7 вы связываете Paths.get(file1) с Paths.get(file2). Попробуйте пример, который я вам привел. Оно работает. - person Paul Smith; 16.11.2013