遍历所有文件
java
List<Path> collect = Files
.walk(Paths.get("D:\\Mirror\\Coding\\python\\nlp"), FileVisitOption.FOLLOW_LINKS)
.collect(Collectors.toList());
collect.forEach(System.out::println);
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
D:\Mirror\Coding\python\nlp
D:\Mirror\Coding\python\nlp\.idea
D:\Mirror\Coding\python\nlp\.idea\inspectionProfiles
D:\Mirror\Coding\python\nlp\.idea\inspectionProfiles\profiles_settings.xml
D:\Mirror\Coding\python\nlp\.idea\misc.xml
D:\Mirror\Coding\python\nlp\.idea\modules.xml
D:\Mirror\Coding\python\nlp\.idea\nlp.iml
D:\Mirror\Coding\python\nlp\.idea\workspace.xml
D:\Mirror\Coding\python\nlp\nlp.py
D:\Mirror\Coding\python\nlp\nlp_service.py
java
List<Path> collect = Files
.walk(Paths.get("D:\\Mirror\\Coding\\python\\nlp"), FileVisitOption.FOLLOW_LINKS)
.collect(Collectors.toList());
collect.forEach(c -> System.out.println(c.getFileName()));
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
nlp
.idea
inspectionProfiles
profiles_settings.xml
misc.xml
modules.xml
nlp.iml
workspace.xml
nlp.py
nlp_service.py
列出有所有文件夹
java
try (Stream<Path> walk = Files.walk(Paths.get("D:\\Mirror\\Coding\\python\\nlp"))) {
List<String> result = walk.filter(Files::isDirectory)
.map(Path::toString).collect(Collectors.toList());
result.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}
列出所有py结尾的
java
try (Stream<Path> walk = Files.walk(Paths.get("D:\\Mirror\\Coding\\python\\nlp"))) {
List<String> result = walk.map(Path::toString)
.filter(f -> f.endsWith(".py"))
.collect(Collectors.toList());
result.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}