1. Introduction
The listFiles(FilenameFilter filter) method returns an array of File
objects that represent the files and directories that satisfy the specified filter. In case the given filter is null then all pathnames are accepted.
2. Method signature
Parameters:
- FilenameFilter filter - a filename filter
Returns
- File
[]
- an array ofFile
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. Sample Java snippet that prints only files (!file.isDirectory()
) with the .txt
extension (s.endsWith(".txt")
)
The output:
4. Conclusion
In this article, we presented a method to list files that satisfy the specified filter. The listFiles(FilenameFilter filter)
method is similar to list(FilenameFilter filter)
but in this case, we have a handler to files no just the name in a string.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}