1. Introduction
The listFiles(FileFilter filter) method returns an array of File
objects that represent the files and directories that satisfy specified FileFilter
.
2. Method signature
Parameters:
- FileFilter filter - a file filter
Returns
- File
[]
- an array of File objects that represent files and directories that satisfy the specified filter.
Throws
- SecurityException - when we do not have access to the file or directory
3. Examples
3.1. Code snippet that prints only files (!file.isDirectory()) with the .txt extension (file.getName().endsWith(".txt"))
The output:
4. Conclusion
In this article, we presented the listFiles(FileFilter filter) method that could be used to filter files and directories from the specified path in the filesystem using FileFilter
object.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}