Java 7中可以使用NIO.2的檔案遍歷
阿新 • • 發佈:2018-12-17
package com.record.example; import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; /** * @className : GetFileName.java * @author : * @mtime : 2018-12-17 13:42:44 */ public class GetFileName { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Path initPath = Paths.get("E:\\ant"); Files.walkFileTree(initPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { System.out.println(file.getFileName().toString()); return FileVisitResult.CONTINUE; } }); } }