Clean Java

There is always a bigger game

Wildcard File Filter in java.

with one comment

Apache common give a useful class named WildcardFileFilter to filter/open files using a wildcardfilter. A simple example of wild card filter is *_2012-01-10*.txt.

package org.sanju.file;

import java.io.File;
import java.io.FileFilter;

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

public class FileUtil {

    public File[] loadFiles(String location, String fileName) {

        File dir = new File(location);
        FileFilter fileFilter = new WildcardFileFilter(fileName);
        return dir.listFiles(fileFilter);
    }

    public static void main(String args[]) throws Exception {
        File[] files = loadFiles("\tmp", "08-12-11_*feed*.dat");
        for (File file : files) {
            System.out.println(file.getName());
            System.out.println(grep(file, "100063"));
        }
    }

}
About these ads

One Response

Subscribe to comments with RSS.

  1. [...] Wildcard File Filter in java. (cleanjava.wordpress.com) [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: