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

Suffix File 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 FileFilterUtils.suffixFileFilter() API. It returns a filter that returns TRUE if the filename ends with the specified suffix.


File Name  :  
com/bethecoder/tutorials/commons_io/tests/filters/SuffixFileFilter.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.FileFilterUtils;

public class SuffixFileFilter {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] args) {
    File directory = new File("C:/input");
    
    String[] files = directory.list(FileFilterUtils.suffixFileFilter(".css"));
     for (String file : files) {
         System.out.println(file);
     }
  }
}
   

It gives the following output,
one.css
three.css
two.css



 
  


  
bl  br