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 |
|
|
Called once for every directory in the file tree. This method is called after all the files in the directory are visited. |
|
|
Called once for every directory in the file tree. This method is called before any of the files in the directory are visited. |
|
|
Called ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access