4 Aralık 2017 Pazartesi

FileVisitor Arayüzü

Giriş
Şu satırı dahil ederiz.
import java.nio.file.FileVisitResult;
import static java.nio.file.FileVisitResult.*;
import java.nio.file.FileVisitor;
Örnek
Şöyle yaparız.
Path path = ...;

Files.walkFileTree(path, new FileVisitor<Path>() {

  @Override
  public FileVisitResult preVisitDirectory(Path dir,
    BasicFileAttributes attrs) throws IOException {
    ...
    return CONTINUE;
  }

  @Override
  public FileVisitResult visitFile(Path file,
    BasicFileAttributes attrs) throws IOException {
    ...
    return CONTINUE;
  }

  @Override
  public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
    ...
    return CONTINUE;
  }

  @Override
  public FileVisitResult postVisitDirectory(Path dir,IOException exc) throws IOException {
    return CONTINUE;
  }
});

Hiç yorum yok:

Yorum Gönder