FilenameFilter

Dear all,

I am pretty new and have the following problem: I want to list specific files from a directory. The files I want to filter have this format:

12e8_H.rsa

12e8_M.rsa

but NOT

12e8_HM.rsa

I have a regexp for it:

.*_[A-Z]?\\.rsa

which worked fine in Perl.

My question is: how can I test the file names in the directory against this expression and store in an array?

I hope I the information I give is enough!

Many thanks, Thomas

[506 byte] By [LordChaosa] at [2007-11-26 19:33:41]
# 1
http://java.sun.com/docs/books/tutorial/essential/regex/
Navy_Codera at 2007-7-9 22:06:25 > top of Java-index,Java Essentials,Java Programming...
# 2

Your title suggests what you should do. First create a FilenameFilter object that implements that regex:FilenameFilter f = new FilenameFilter() {

public boolean accept(File dir, String name) {

// return true if "name" matches the regex and false if not.

}

};

Then use the list() method of File that takes one of those things:File dir = new File(directoryPath);

String[] filteredFiles = dir.list(f);

DrClapa at 2007-7-9 22:06:25 > top of Java-index,Java Essentials,Java Programming...
# 3
> My question is: how can I test the file names in the> directory against this expression and store in an> array?With java.io.File.list(FilenameFilter).
glevnera at 2007-7-9 22:06:25 > top of Java-index,Java Essentials,Java Programming...