Stay organized with collections
Save and categorize content based on your preferences.
SimpleFileVisitor
open class SimpleFileVisitor<T : Any!> : FileVisitor<T>
A simple visitor of files with default behavior to visit all files and to re-throw I/O errors.
Methods in this class may be overridden subject to their general contract.
Summary
Protected constructors |
Initializes a new instance of this class.
|
Public methods |
open FileVisitResult! |
Invoked for a directory after entries in the directory, and all of their descendants, have been visited.
|
open FileVisitResult! |
Invoked for a directory before entries in the directory are visited.
|
open FileVisitResult! |
Invoked for a file in a directory.
|
open FileVisitResult! |
Invoked for a file that could not be visited.
|
Protected constructors
SimpleFileVisitor
protected SimpleFileVisitor()
Initializes a new instance of this class.
Public methods
postVisitDirectory
open fun postVisitDirectory(
dir: T,
exc: IOException!
): FileVisitResult!
Invoked for a directory after entries in the directory, and all of their descendants, have been visited.
Unless overridden, this method returns CONTINUE
if the directory iteration completes without an I/O exception; otherwise this method re-throws the I/O exception that caused the iteration of the directory to terminate prematurely.
Parameters |
dir |
T: a reference to the directory |
exc |
IOException!: null if the iteration of the directory completes without an error; otherwise the I/O exception that caused the iteration of the directory to complete prematurely |
Exceptions |
java.io.IOException |
if an I/O error occurs |
preVisitDirectory
open fun preVisitDirectory(
dir: T,
attrs: BasicFileAttributes!
): FileVisitResult!
Invoked for a directory before entries in the directory are visited.
Unless overridden, this method returns CONTINUE
.
Parameters |
dir |
T: a reference to the directory |
attrs |
BasicFileAttributes!: the directory's basic attributes |
Exceptions |
java.io.IOException |
if an I/O error occurs |
visitFile
open fun visitFile(
file: T,
attrs: BasicFileAttributes!
): FileVisitResult!
Invoked for a file in a directory.
Unless overridden, this method returns CONTINUE
.
Parameters |
file |
T: a reference to the file |
attrs |
BasicFileAttributes!: the file's basic attributes |
Exceptions |
java.io.IOException |
if an I/O error occurs |
visitFileFailed
open fun visitFileFailed(
file: T,
exc: IOException!
): FileVisitResult!
Invoked for a file that could not be visited.
Unless overridden, this method re-throws the I/O exception that prevented the file from being visited.
Parameters |
file |
T: a reference to the file |
exc |
IOException!: the I/O exception that prevented the file from being visited |
Exceptions |
java.io.IOException |
if an I/O error occurs |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# SimpleFileVisitor\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nSimpleFileVisitor\n=================\n\n```\nopen class SimpleFileVisitor\u003cT : Any!\u003e : FileVisitor\u003cT\u003e\n```\n\n|---|--------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [java.nio.file.SimpleFileVisitor](#) |\n\nA simple visitor of files with default behavior to visit all files and to re-throw I/O errors.\n\nMethods in this class may be overridden subject to their general contract.\n\nSummary\n-------\n\n| Protected constructors ||\n|-----------------------------------------------------------------------------------------|---|\n| [SimpleFileVisitor](#SimpleFileVisitor())`()` Initializes a new instance of this class. |\n\n| Public methods ||\n|--------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [FileVisitResult](/reference/kotlin/java/nio/file/FileVisitResult)! | [postVisitDirectory](#postVisitDirectory(java.nio.file.SimpleFileVisitor.T,%20java.io.IOException))`(`dir:` `T`, `exc:` `[IOException](../../io/IOException.html#)!`)` Invoked for a directory after entries in the directory, and all of their descendants, have been visited. |\n| open [FileVisitResult](/reference/kotlin/java/nio/file/FileVisitResult)! | [preVisitDirectory](#preVisitDirectory(java.nio.file.SimpleFileVisitor.T,%20java.nio.file.attribute.BasicFileAttributes))`(`dir:` `T`, `attrs:` `[BasicFileAttributes](/reference/kotlin/java/nio/file/attribute/BasicFileAttributes)!`)` Invoked for a directory before entries in the directory are visited. |\n| open [FileVisitResult](/reference/kotlin/java/nio/file/FileVisitResult)! | [visitFile](#visitFile(java.nio.file.SimpleFileVisitor.T,%20java.nio.file.attribute.BasicFileAttributes))`(`file:` `T`, `attrs:` `[BasicFileAttributes](/reference/kotlin/java/nio/file/attribute/BasicFileAttributes)!`)` Invoked for a file in a directory. |\n| open [FileVisitResult](/reference/kotlin/java/nio/file/FileVisitResult)! | [visitFileFailed](#visitFileFailed(java.nio.file.SimpleFileVisitor.T,%20java.io.IOException))`(`file:` `T`, `exc:` `[IOException](../../io/IOException.html#)!`)` Invoked for a file that could not be visited. |\n\nProtected constructors\n----------------------\n\n### SimpleFileVisitor\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nprotected SimpleFileVisitor()\n```\n\nInitializes a new instance of this class.\n\nPublic methods\n--------------\n\n### postVisitDirectory\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun postVisitDirectory(\n dir: T, \n exc: IOException!\n): FileVisitResult!\n```\n\nInvoked for a directory after entries in the directory, and all of their descendants, have been visited.\n\nUnless overridden, this method returns [CONTINUE](/reference/kotlin/java/nio/file/FileVisitResult) if the directory iteration completes without an I/O exception; otherwise this method re-throws the I/O exception that caused the iteration of the directory to terminate prematurely.\n\n| Parameters ||\n|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `dir` | T: a reference to the directory |\n| `exc` | [IOException](../../io/IOException.html#)!: `null` if the iteration of the directory completes without an error; otherwise the I/O exception that caused the iteration of the directory to complete prematurely |\n\n| Return ||\n|---------------------------------------------------------------------|------------------|\n| [FileVisitResult](/reference/kotlin/java/nio/file/FileVisitResult)! | the visit result |\n\n| Exceptions ||\n|-----------------------|------------------------|\n| `java.io.IOException` | if an I/O error occurs |\n\n### preVisitDirectory\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun preVisitDirectory(\n dir: T, \n attrs: BasicFileAttributes!\n): FileVisitResult!\n```\n\nInvoked for a directory before entries in the directory are visited.\n\nUnless overridden, this method returns [CONTINUE](/reference/kotlin/java/nio/file/FileVisitResult).\n\n| Parameters ||\n|---------|-------------------------------------------------------------------------------------------------------------------------|\n| `dir` | T: a reference to the directory |\n| `attrs` | [BasicFileAttributes](/reference/kotlin/java/nio/file/attribute/BasicFileAttributes)!: the directory's basic attributes |\n\n| Return ||\n|---------------------------------------------------------------------|------------------|\n| [FileVisitResult](/reference/kotlin/java/nio/file/FileVisitResult)! | the visit result |\n\n| Exceptions ||\n|-----------------------|------------------------|\n| `java.io.IOException` | if an I/O error occurs |\n\n### visitFile\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun visitFile(\n file: T, \n attrs: BasicFileAttributes!\n): FileVisitResult!\n```\n\nInvoked for a file in a directory.\n\nUnless overridden, this method returns [CONTINUE](/reference/kotlin/java/nio/file/FileVisitResult).\n\n| Parameters ||\n|---------|--------------------------------------------------------------------------------------------------------------------|\n| `file` | T: a reference to the file |\n| `attrs` | [BasicFileAttributes](/reference/kotlin/java/nio/file/attribute/BasicFileAttributes)!: the file's basic attributes |\n\n| Return ||\n|---------------------------------------------------------------------|------------------|\n| [FileVisitResult](/reference/kotlin/java/nio/file/FileVisitResult)! | the visit result |\n\n| Exceptions ||\n|-----------------------|------------------------|\n| `java.io.IOException` | if an I/O error occurs |\n\n### visitFileFailed\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun visitFileFailed(\n file: T, \n exc: IOException!\n): FileVisitResult!\n```\n\nInvoked for a file that could not be visited.\n\nUnless overridden, this method re-throws the I/O exception that prevented the file from being visited.\n\n| Parameters ||\n|--------|----------------------------------------------------------------------------------------------------------|\n| `file` | T: a reference to the file |\n| `exc` | [IOException](../../io/IOException.html#)!: the I/O exception that prevented the file from being visited |\n\n| Return ||\n|---------------------------------------------------------------------|------------------|\n| [FileVisitResult](/reference/kotlin/java/nio/file/FileVisitResult)! | the visit result |\n\n| Exceptions ||\n|-----------------------|------------------------|\n| `java.io.IOException` | if an I/O error occurs |"]]