问题
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.
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.
回答1:
Source and target are paths not filenames. change your code to:
Files.createSymbolicLink(Paths.get(sourceFileName), Paths.get(targetFileName));
来源:https://stackoverflow.com/questions/18009545/symlink-with-files-createsymboliclink-java-7-in-rhel-5