Apache Commons IO Tutorial
Selected Reading
- Apache Commons IO - Discussion
- Apache Commons IO - Useful Resources
- Apache Commons IO - Quick Guide
- Apache Commons IO - TeeOutputStream
- Apache Commons IO - TeeInputStream
- LastModifiedFileComparator
- Apache Commons IO - SizeFileComparator
- Apache Commons IO - NameFileComparator
- Apache Commons IO - FileAlterationMonitor
- Apache Commons IO - FileAlterationObserver
- Apache Commons IO - FileEntry
- Apache Commons IO - AndFileFilter
- Apache Commons IO - OrFileFilter
- Apache Commons IO - PrefixFileFilter
- Apache Commons IO - SuffixFileFilter
- Apache Commons IO - WildcardFileFilter
- Apache Commons IO - NameFileFilter
- Apache Commons IO - LineIterator
- Apache Commons IO - IOCase
- Apache Commons IO - FileSystemUtils
- Apache Commons IO - FilenameUtils
- Apache Commons IO - FileUtils
- Apache Commons IO - IOUtils
- Apache Commons IO - Environment Setup
- Apache Commons IO - Overview
- Apache Commons IO - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache Commons IO - WildcardFileFilter
Apache Commons IO - WildcardFileFilter
WildcardFileFilter in Commons IO filters the files using the suppped wildcards.
Class Declaration
Following is the declaration for org.apache.commons.io.filefilter.WildcardFileFilter Class −
pubpc class WildcardFileFilter extends AbstractFileFilter implements Seriapzable
Example of WildcardFileFilter Class
Here is the input file we need to parse
Welcome to TutorialsPoint. Simply Easy Learning.
Let s print all files and directories in the current directory and then, filter a file whose name ends with t.
IOTester.java
import java.io.File; import java.io.IOException; import org.apache.commons.io.filefilter.WildcardFileFilter; pubpc class IOTester { pubpc static void main(String[] args) { try { usingWildcardFileFilter(); } catch(IOException e) { System.out.println(e.getMessage()); } } pubpc static void usingWildcardFileFilter() throws IOException { //get the current directory File currentDirectory = new File("."); //get names of all files and directory in current directory String[] files = currentDirectory.pst(); System.out.println("All files and Folders. "); for( int i = 0; i < files.length; i++ ) { System.out.println(files[i]); } System.out.println(" File name ending with t. "); String[] filesNames = currentDirectory.pst( new WildcardFileFilter("*t")); for( int i = 0; i < filesNames.length; i++ ) { System.out.println(filesNames[i]); } } }
Output
It will print the following result.
All files and Folders. .classpath .project .settings bin input.txt src File name ending with t .project input.txtAdvertisements