Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : F words : Filter.
String[] fileNames = file. list( someFilter );
will get list of files in this directory. Wildcards won't work. Note it returns an array of Strings, not including the directory, not File objects. Files are not in any particular order. They include the subdirectories, but not the . or .. entries.
Your FilenameFilter needs at a minimum to filter with File.isDirectory().
You can also use FileDialog.setFilenameFilter(java.io.FilenameFilter) to restrict which files are displayed in a File choosing dialog.
I have written 10 FilenameFilters with source. All are trivial except for the MultiFilter that lets you combine other filters in various ways.
They come with Java source. The collection is mainly for newbies trying to get some ideas on how FilenameFilters work and how you could write them.
| FilenameFilters | |
|---|---|
| Name | Purpose |
| AllDirectoriesFilter | gets all directories |
| AllFilesFilter | gets all files |
| ClamFilter | simple wildcard |
| EverythingFilter | gets everything |
| FileLengthFilter | gets short or long files |
| FileNameLengthFilter | gets short or long filenames |
| ListFilter | gets a list of files |
| MultiFilter | combines other Filters with "consider", "must" and "never". |
| RecentFilter | filters based on lastModified date |
| RegexFilter | filters with Regex expressions. |
You can cascade (combine) FileNameFilters by having one ask advice of another, or write a mother filter that asks the advice of several child filters and &&'s or ||'s the results of their accept methods. MultiFilter makes that task easy.
If you are selecting files to display in Swing, the classes of interest are: javax.swing.filechooser.FileFilter, javax.swing.JFileChooser, javax.swing.plaf.BasicFileChooserUI, javax.swing.plaf.multi.MultiFileChooserUI.
In the context of Servlets, javax.servlet.Filter is an interface to allow a transaction to be processed in an assembly line. Each Filter does some of the work and passes on the input or output to the next filter in the chain, and decides on who is next.
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 2520. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/filter.html | J:\mindprod\jgloss\filter.html | |||