Sai Sunder
Sai Sunder

Reputation: 1021

java.io.FileNameFilter

interface FilenameFilter {
    boolean accept(File dir, String name);
}

As Far as I know FileNameFilter is used to select files based on specific pattern or extension. For that 'String name' alone is enough. Why the 'File dir' parameter is required? Is there any specific reason or use for that?

Upvotes: 1

Views: 497

Answers (4)

Alya'a Gamal
Alya'a Gamal

Reputation: 5638

The dir object is the parent directory of the file, and name is the name of the file.


accept

public boolean accept(File dir,
                      String name)

Checks to see if the File should be accepted by this filter.

Specified by:

accept in interface FilenameFilter

Specified by: accept in interface IOFileFilter

Parameters:

dir - the directory File to check

name - the filename within the directory to check

Returns:

true if this file matches the test


Upvotes: 2

Achintya Jha
Achintya Jha

Reputation: 12843

Interface FilenameFilter

Instances of classes that implement this interface are used to filter filenames. These instances are used to filter directory listings in the list method of class File, and by the Abstract Window Toolkit's file dialog component.

Upvotes: 0

CAMOBAP
CAMOBAP

Reputation: 5657

FilenameFilter - just interface.

You can write your own implementation that will be care about dir where file placed

Upvotes: 1

rajesh
rajesh

Reputation: 3407

Check the docs

Parameters:
dir - the directory in which the file was found.
name - the name of the file.

Upvotes: 0

Related Questions