Name
FileFilter
Synopsis
This interface, added in Java 1.2,
defines an accept( )
method that filters a list of
files. You can list the contents of a
directory by calling the
listFiles( )
method of the File
object that represents the desired directory. If you want a filtered
listing, such as a listing of files but not subdirectories or a
listing of files whose names end in .class, you
can pass a FileFilter
object to
listFiles( )
. For each entry in the directory, a
File
object is passed to the accept(
)
method. If accept( )
returns
true
, that File
is included in
the return value of listFiles( )
. If
accept( )
returns false, that entry is not
included in the listing. Use FilenameFilter
if
compatibility with previous releases of Java is required or if you
prefer to filter filenames (i.e., String
objects)
rather than File
objects.
public interface FileFilter { // Public Instance Methods boolean accept(File pathname); }
Passed To
File.listFiles( )
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.