创建具有权限的符号链接
import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; /** 来 自 时代Java公众号 - nowjava.com **/ import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.PosixFileAttributes; import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; import java.util.Set; public class Main { public static void main(String[] args) { // create a symbolic link with permissions Path link2 = FileSystems.getDefault().getPath("test"); Path target2 = FileSystems.getDefault().getPath("C:/folder1/photos", "test.jpg"); /** 时 代 J a v a - nowjava.com 提供 **/ try { PosixFileAttributes attrs = Files.readAttributes(target2, PosixFileAttributes.class); FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions .asFileAttribute(attrs.permissions()); Files.createSymbolicLink(link2, target2, attr); } catch (IOException | UnsupportedOperationException | SecurityException e) { if (e instanceof SecurityException) { System.err.println("Permission denied!"); } if (e instanceof