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
- FilenameFilter filter - a filename filter
- an array of
Fileobjects that represent files and directories that satisfy the specified filter.
- SecurityException - when we do not have access to the file or directory
3.1. Sample Java snippet that prints only files (
!file.isDirectory()) with the
.txt extension (
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.