tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons IO > Filters > Regex Filter

Regex Filter 

Apache Commons IO is a java library with simple IO utilities and filters. This requires the library commons-io-2.1.jar to be in classpath. The following example shows using RegexFileFilter filter. It returns TRUE if the file name matches the given regular expression.


File Name  :  
com/bethecoder/tutorials/commons_io/tests/filters/RegexFilterTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_io.tests.filters;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.filefilter.RegexFileFilter;

public class RegexFilterTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] args) {
    File directory = new File("C:/input");

    //Name starting with 't/T' and ending with 'ss'
    String[] files = directory.list(new RegexFileFilter("^[tT].*ss$"));
    for (String file : files) {
      System.out.println(file);
    }
  }
}
   

It gives the following output,
Test.class
three.css
two.css



 
  


  
bl  br