我正在尝试为没有目标的符号链接更改lastModifiedTime值。
例如:foo-> 无
我可以lastModifiedTime使用... 访问值
String fooPath = "/Users/me/test/foo";
Path path = new File(fooPath).toPath();
FileTime t = Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS);
Run Code Online (Sandbox Code Playgroud)
但是,我无法使用下面的代码段设置相同的符号链接;这给了我java.nio.file.NoSuchFileException目标
String fooPath = "/Users/me/test/foo";
Path path = new File(fooPath).toPath();
FileTime t = FileTime.fromMillis(date.getTime());
Files.setLastModifiedTime(path, t);
Run Code Online (Sandbox Code Playgroud)
我什至尝试手动设置属性,但这使我出现java.nio.file.FileSystemException“符号链接级别过多或无法访问符号链接的属性”错误:
Files.setAttribute(path, "lastModifiedTime", t, LinkOption.NOFOLLOW_LINKS);
Run Code Online (Sandbox Code Playgroud)
我不想走系统调用路线,因为我需要跨平台支持。