SimpleFileVisitor Class
Package: java.nio.file
The SimpleFileVisitor class is a default implementation of the FileVisitor interface. This interface is used along with the walkFileTree method of the Files class to process all of the files in a given directory tree, including files in subdirectories. For more information, see FileVisitor Interface and Files 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 once for every file in the file tree. |
|
|
Called if the file couldn’t be accessed. |
The following is an overview of what you must do to use the SimpleFileVisitor class to walk the contents of a directory tree:
1. Create a file visitor class that extends SimpleFileVisitor
.
The SimpleFileVisitor class implements the four required methods of the FileVisitor class, providing default implementations for each method.
2. In your file visitor class, override one or more SimpleFileVisitor
methods.
These methods are where you write the code that you want to execute for every file visited when the directory ...
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