Apache Commons IO - Utility Classes
- Apache Commons IO - IOUtils
- Apache Commons IO - FileUtils
- Apache Commons IO - FilenameUtils
- Apache Commons IO - FileSystemUtils
- Apache Commons IO - IOCase
- Apache Commons IO - LineIterator
Apache Commons IO - Filter Classes
- Apache Commons IO - NameFileFilter
- Apache Commons IO - WildcardFileFilter
- Apache Commons IO - SuffixFileFilter
- Apache Commons IO - PrefixFileFilter
- Apache Commons IO - OrFileFilter
- Apache Commons IO - AndFileFilter
- Apache Commons IO - FileEntry
Apache Commons IO - Comparator Classes
- Apache Commons IO - NameFileComparator
- Apache Commons IO - SizeFileComparator
- LastModifiedFileComparator
Apache Commons IO - Stream Classes
Apache Commons IO - Useful Resources
Apache Commons IO - WildcardFileFilter Class
Overview
WildcardFileFilter class in Commons IO filters the files using the supplied wildcards.
Class Declaration
Following is the declaration for org.apache.commons.io.filefilter.WildcardFileFilter Class −
public class WildcardFileFilter extends AbstractFileFilter implements Serializable
Here is the input file we need to parse −
input.txt
Welcome to TutorialsPoint. Simply Easy Learning.
Example - Filtering a file names ending with t.
CommonsIoTester.java
package com.tutorialspoint;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.filefilter.WildcardFileFilter;
public class CommonsIoTester {
public static void main(String[] args) throws IOException {
//get the current directory
File currentDirectory = new File(".");
System.out.println("\nFile name ending with t.\n");
WildcardFileFilter filter = WildcardFileFilter.builder().setWildcards("*t").get();
String[] filesNames = currentDirectory.list(filter);
for( int i = 0; i < filesNames.length; i++ ) {
System.out.println(filesNames[i]);
}
}
}
Output
It will print the following result −
File name ending with t. .project input.txt output.txt
Example - Filtering a file names starting with i.
CommonsIoTester.java
package com.tutorialspoint;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.filefilter.WildcardFileFilter;
public class CommonsIoTester {
public static void main(String[] args) throws IOException {
//get the current directory
File currentDirectory = new File(".");
System.out.println("\nFile name starting with i.\n");
WildcardFileFilter filter = WildcardFileFilter.builder().setWildcards("i*").get();
String[] filesNames = currentDirectory.list(filter);
for( int i = 0; i < filesNames.length; i++ ) {
System.out.println(filesNames[i]);
}
}
}
Output
It will print the following result −
File name starting with i. input.txt
Advertisements