| Prev Package | Next Package | Frames | No Frames |
java.io.FileFilter and java.io.FilenameFilter.Interface Summary | |
| ConditionalFileFilter | Defines operations for conditional file filters. |
| IOFileFilter | An interface which brings the FileFilter and FilenameFilter interfaces together. |
Class Summary | |
| AbstractFileFilter | An abstract class which implements the Java FileFilter and FilenameFilter interfaces via the IOFileFilter interface. |
| AgeFileFilter | Filters files based on a cutoff time, can filter either older or newer files. |
| AndFileFilter | A java.io.FileFilter providing conditional AND logic across a list of
file filters. |
| DelegateFileFilter | This class turns a Java FileFilter or FilenameFilter into an IO FileFilter. |
| DirectoryFileFilter | This filter accepts Files that are directories. |
| FalseFileFilter | A file filter that always returns false. |
| FileFilterUtils | Useful utilities for working with file filters. |
| NameFileFilter | Filters filenames for a certain name. |
| NotFileFilter | This filter produces a logical NOT of the filters specified. |
| OrFileFilter | A java.io.FileFilter providing conditional OR logic across a list of
file filters. |
| PrefixFileFilter | Filters filenames for a certain prefix. |
| SizeFileFilter | Filters files based on size, can filter either larger or smaller files as compared to a given threshold. |
| SuffixFileFilter | Filters files based on the suffix (what the filename ends with). |
| TrueFileFilter | A file filter that always returns true. |
| WildcardFilter | Filters files using supplied wildcard(s). |
java.io.FileFilter and java.io.FilenameFilter. Besides
that the package offers a series of ready-to-use implementations of the
IOFileFilter interface including implementation that allow you to combine
other such filters.
These filter can be used to list files or in java.awt.FileDialog,
for example.
There are a number of 'primitive' filters:
| DirectoryFilter | Only accept directories |
| PrefixFileFilter | Filter based on a prefix |
| SuffixFileFilter | Filter based on a suffix |
| NameFileFilter | Filter based on a filename |
| WildcardFileFilter | Filter based on wildcards |
| AgeFileFilter | Filter based on last modified time of file |
| SizeFileFilter | Filter based on file size |
| TrueFileFilter | Accept all files |
| FalseFileFilter | Accept no files |
| NotFileFilter | Applies a logical NOT to an existing filter |
| AndFileFilter | Combines two filters using a logical AND |
| OrFileFilter | Combines two filter using a logical OR |
File dir = new File(".");
String[] files = dir.list(
new AndFileFilter(
new AndFileFilter(
new PrefixFileFilter("A"),
new OrFileFilter(
new SuffixFileFilter(".class"),
new SuffixFileFilter(".java")
)
),
new NotFileFilter(
new DirectoryFileFilter()
)
)
);
for ( int i=0; i<files.length; i++ ) {
System.out.println(files[i]);
}
This package also contains a utility class:
FileFilterUtils. It allows you to use all
file filters without having to put them in the import section. Here's how the
above example will look using FileFilterUtils:
File dir = new File(".");
String[] files = dir.list(
FileFilterUtils.andFileFilter(
FileFilterUtils.andFileFilter(
FileFilterUtils.prefixFileFilter("A"),
FileFilterUtils.orFileFilter(
FileFilterUtils.suffixFileFilter(".class"),
FileFilterUtils.suffixFileFilter(".java")
)
),
FileFilterUtils.notFileFilter(
FileFilterUtils.directoryFileFilter()
)
)
);
for ( int i=0; i<files.length; i++ ) {
System.out.println(files[i]);
}
There are a few other goodies in that class so please have a look at the
documentation in detail.