集册 Java实例教程 启动递归过程

启动递归过程

欢马劈雪     最近更新时间:2020-01-02 10:19:05

387
启动递归过程

import java.io.IOException;

import java.nio.file.FileVisitResult;

import java.nio.file.Files;

import java.nio.file.Path;
/*
N o w J a v a . c o m - 时代Java
*/

import java.nio.file.Paths;

import java.nio.file.SimpleFileVisitor;


public class Main {

  public static void main(String[] args) throws Exception {

    Path listDir = Paths.get("C:/folder1"); // define the starting file tree

    ListTree walk = new ListTree(); // instantiate the walk


    try {

      Files.walkFileTree(listDir, walk); // start the walk

    } catch (IOException e) {

      System.err.println(e);

    }

  }

}/** nowjava - 时代Java 提 供 **/


class ListTree extends SimpleFileVisitor<Path> {


  @Override

  public FileVisitResult postVisitDirectory(Path dir, IOException exc) {


    System.out.println("Visited directory: " + dir.toString());


    return 
展开阅读全文