Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

ExtensionFilenameFilter



The ExtensionFilenameFilter class is a file filter which is both: It allows to define a file filter which filters files depending on their extension.

For example with only one extension:
   ExtensionFilenameFilter filter = new ExtensionFilenameFilter("PNG images", "png");      

Using a vararg for the array of extensions

The ExtensionFilenameFilter.createFromExtensionsAndDesc(String, String...) allows to use a vararg for the array of extensions.

The ExtensionFilenameFilter.createFromExtensions(String...) allows to use a vararg for the array of extensions and a description (the descrition will be constructed with the extensions).

For example with providing the extensions and the description of the filter:
   ExtensionFilenameFilter filter = ExtensionFilenameFilter.createFromExtensionsAndDesc("Images", "png", "jpg");     
Or with providing only the extensions (the description will be constructed automatically by using the naes of the extensions):
   ExtensionFilenameFilter filter = ExtensionFilenameFilter.createFromExtensions("png", "jpg"); // the description wlll be "png, jpg files"

Pattern for the extension

You can specify the extension with or without a dot at the beginning of the String. For example both ExtensionFilenameFilter filter = new ExtensionFilenameFilter("PNG images", "png") and ExtensionFilenameFilter filter = new ExtensionFilenameFilter("PNG images", ".png") will specify files with the "png" extension.

Also the extension is not case-sensitive. For example ExtensionFilenameFilter filter = new ExtensionFilenameFilter("PNG", "PNG images") specifies the same extension.

Examples

With only one extension:
   ExtensionFilenameFilter filter = new ExtensionFilenameFilter("PNG images", "png");      
With several extensions:
   String[] images = {"png", "jpg"};
   ExtensionFilenameFilter filter = new ExtensionFilenameFilter(images, "Images");      

See also


Categories: Io | Packages

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences