FileVisitor Interface

Package: java.nio.file

The FileVisitor interface defines four methods that must be implemented for a file visitor class, which can be used to walk a directory tree and process every file within every folder in the tree. (“Walking a tree” refers to the process of retrieving every file and directory in a given directory as well as in all of its subdirectories.)

FileVisitor is used in conjunction with the walkFileTree method of the Files class. To use that method, you must first create a class that implements the FileVisitor interface. You can do that by creating your own class that implements FileVisitor and implementing each of the FileVisitor methods. Or, you can create a class that extends the SimpleFileVisitor class and override those methods that you wish to provide your own implementation for.

For more information about the walkFileTree method, see Files Class. For more information about the Simple FileVisitor class and a sample class that extends SimpleFileVisitor, see SimpleFileVisitor Class.

Methods

Method

Description

FileVisitResult post VisitDirectory(T dir, IOException e)

Called once for every directory in the file tree. This method is called after all the files in the directory are visited.

FileVisitResult pre VisitDirectory(T dir)

Called once for every directory in the file tree. This method is called before any of the files in the directory are visited.

FileVisitResult visitFile(T file, BasicFileAttributes attr)

Called once for every file in the file tree.

FileVisitResult visitFileFailed(T file, IOException e)

Called if the file couldn’t be accessed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset