使用与目标相同的lastModifiedTime和lastAccessTime创建符号链接
import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files;// 来 自 N o w J a v a . c o m - 时代Java import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.attribute.FileTime; public class Main { public static void main(String[] args) { // create a symbolic link with the same lastModifiedTime and lastAccessTime // as the target Path link3 = FileSystems.getDefault().getPath("test"); Path target3 = FileSystems.getDefault().getPath("C:/folder1/photos", "test.jpg");//时 代 Java 公 众 号 - nowjava.com 提 供 try { Files.createSymbolicLink(link3, target3); FileTime lm = (FileTime) Files.getAttribute(target3, "basic:lastModifiedTime", LinkOption.NOFOLLOW_LINKS); FileTime la = (FileTime) Files.getAttribute(target3, "basic:lastAccessTime", LinkOption.NOFOLLOW_LINKS); Files.setAttribute(link3, "basic:lastModifiedTime", lm, LinkOption.NOFOLLOW_LINKS); Files.setAttribute(link3, "basic:lastAccessTime", la, LinkOption.NOFOLLOW_LINKS); } catch (IOException | UnsupportedOperationException | SecurityException e) { if (e instanceof SecurityException) { System.err.println("Permision denied!"); } if (e