Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Beginner
Sep 6, 2011



Application Security Testing: An Integral Part of DevOps

Java Code to Filter File Names in a Directory

The following Java code does the following:

  1. Filters files for an array of extensions.
  2. Splits file names.
  3. Tests the resulting array
package FileHandling;

import java.io.File;
import java.io.FilenameFilter;

 * filters files for an array of extensions critstr
 * splitting file name by splitstr
 * last element of resulting array being tested

 * @author emniyet
public final class MyFileFilter implements FilenameFilter {

    private String [] critstr;
    private String splitstr;
     public void setCriteria(String splitstr, String [] critstr) {

     public boolean accept(File dir, String name) {
         boolean res=false;
         String [] string = name.split(splitstr);
        for (int j=0;j<critstr.lengthj++){ 
        if(string[string.length-1].equalsIgnoreCase(critstr[j])) {
            break Y;

        return res;

code fragment using the FileNameFilter.
            File fil = new File("C:\\"
                        + "Users\\"
                        + "emniyet\\"
                        + "Documents\\"
                        + "NetBeansProjects\\"
                        + "JSaat\\"
                         + "src\\"
                         + "JSaatSaat\\");
            MyFileFilter flt = new MyFileFilter();
            String [] crit= {"wav", "au", "mid"};
            flt.setCriteria("\\.", crit); 
             this.adclip = fil.list(flt);
            for(int j=0;j
deniz mermerci
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date