Use Files.walkFileTree
, it will recursively show your sub-directory corresponding to your parent directory.
public static void main(String[] args) throws IOException {
Path startingDir = Paths
.get("C:\\projects\\workspace\testing");
Files.walkFileTree(startingDir, new FindJavaVisitor());
}
private static class FindJavaVisitor extends SimpleFileVisitor {
@Override
public FileVisitResult preVisitDirectory(Path dir,
BasicFileAttributes attrs) throws IOException {
if(dir.getFileName().toAbsolutePath().toString().contains("z1")){
System.out.println("z1 is found at"+ dir.getFileName().toAbsolutePath());
}
return FileVisitResult.CONTINUE;
}
}