import lombok.extern.slf4j.Slf4j; import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.concurrent.atomic.AtomicInteger; @Slf4j public class TestFileWalkFileTree { public static void main(String[] args) throws IOException { AtomicInteger dirCount=new AtomicInteger(); AtomicInteger fileCount=new AtomicInteger(); Files.walkFileTree(Paths.get("C:\\userper\\文档\\itcs-business\\itcs-business\\st-framework-api"),new SimpleFileVisitor<Path>(){ @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { System.out.println("===>"+dir); dirCount.incrementAndGet(); return super.preVisitDirectory(dir, attrs); } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { fileCount.incrementAndGet(); System.out.println("-->"+file); return super.visitFile(file, attrs); } }); log.info("遍历文件夹数量:{},文件数量:{}",dirCount,fileCount); } }