Link to home
Start Free TrialLog in
Avatar of Swaminathan K
Swaminathan KFlag for India

asked on

Difference between FilenameFilter and FileFilter interfaces

Need help on two interfaces in Java/ I want to know the difference between
FilenameFilter and FileFilter interfaces in Java. Both have the same accept method , but onlky difference being number of and type of parameter in each interface.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Well the other difference of course is that one is gui-specific. The other, (in java.io) i've found to be slightly more flexible as you don't need to separate the name from the directory
Avatar of gsk
gsk

Hi Sam,

The FilenameFilter returns an array of abstract pathnames indicating the files and directories in the directory indicated by this abstract pathname that satisfy the specified filter.when we have to find all files with a certain extension only any do some operations on those files such as deleting them (like file ending with .log or .tmp extension like error.log or  history.tmp etc

TheFileFilter -
where we have to work with a particular type of files inside a directory. “java.io.FileFilter” class is present in IO package for these type of purposes only

public interface FileFilter
{
   public abstract boolean accept(File file);
}

 It contains only one method and this method takes a File instance as parameter and returns true/false whether if file present or not.
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
They are actually both in java.io, not sure which one you think is somewhere else too.
Sorry - was thinking of  javax.swing.filechooser.FileFilter