为什么 Files.walk(path, FileVisitOption.FOLLOW_LINKS) 不关注链接?
Why Files.walk(path, FileVisitOption.FOLLOW_LINKS) not following links?
在我的 Mac OS X 上,我有以下文件层次结构:
(base) bohaoli@bunnyBoom-2:~/Desktop/tuto/tuto_link$ tree
.
├── a
│ └── b
│ ├── c
│ │ └── d
│ └── link -> /Users/bohaoli/Desktop/tuto/tuto_link/e/f/g/h/cousin.txt
└── e
└── f
└── g
└── h
└── cousin.txt
但是下面代码的最后两行
Path path = Paths.get("/Users/bohaoli/Desktop/tuto/tuto_link/a");
Files.walk(path, FileVisitOption.FOLLOW_LINKS).forEach(System.out::println);
Files.walk(path).forEach(System.out::println);
给出相同的结果:
/Users/bohaoli/Desktop/tuto/tuto_link/a
/Users/bohaoli/Desktop/tuto/tuto_link/a/b
/Users/bohaoli/Desktop/tuto/tuto_link/a/b/link
/Users/bohaoli/Desktop/tuto/tuto_link/a/b/c
/Users/bohaoli/Desktop/tuto/tuto_link/a/b/c/d
为什么即使我提供了 FileVisitOption.FOLLOW_LINKS 选项也无法访问链接?
在我的 Mac OS X 上,我有以下文件层次结构:
(base) bohaoli@bunnyBoom-2:~/Desktop/tuto/tuto_link$ tree
.
├── a
│ └── b
│ ├── c
│ │ └── d
│ └── link -> /Users/bohaoli/Desktop/tuto/tuto_link/e/f/g/h/cousin.txt
└── e
└── f
└── g
└── h
└── cousin.txt
但是下面代码的最后两行
Path path = Paths.get("/Users/bohaoli/Desktop/tuto/tuto_link/a");
Files.walk(path, FileVisitOption.FOLLOW_LINKS).forEach(System.out::println);
Files.walk(path).forEach(System.out::println);
给出相同的结果:
/Users/bohaoli/Desktop/tuto/tuto_link/a
/Users/bohaoli/Desktop/tuto/tuto_link/a/b
/Users/bohaoli/Desktop/tuto/tuto_link/a/b/link
/Users/bohaoli/Desktop/tuto/tuto_link/a/b/c
/Users/bohaoli/Desktop/tuto/tuto_link/a/b/c/d
为什么即使我提供了 FileVisitOption.FOLLOW_LINKS 选项也无法访问链接?