jQuery in Action, 2nd edition
The moose likes Java in General and the fly likes Pattern-based file/class searching Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Pattern-based file/class searching" Watch "Pattern-based file/class searching" New topic
Author

Pattern-based file/class searching

Sathya Sekar
Greenhorn

Joined: Dec 17, 2003
Posts: 15
Hello friends,

I am not sure if this fits in the "Basic" section or here. So pardon me if I am posting in the incorrect forum.

I have a requirement to load all XML files on the classpath that have a "table" in their name. In Unix terms, this might mean something like:

find . -name *table*.xml

Can this be achieved in Java? (I mean the functionality, not the script execution )

Also, on similar lines, is it possible to get all classes which have a name with following a patter or all classes that have implemented a specific interface?

Thanks.
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
What do you mean "load all XML files"?

Whatever little I understand from above problem, see if the below steps help:
1. Get the classpath settings at run-time. You can use System.getProperty ("java.class.path"). This gives the complete filepaths.
2. Find all the files with .xml extension as File objects in the above filepaths
3. Process the files that match your criteria i.e. File names having "table" in it.

You can try the same approach for you second question also.


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

File has two method called listFiles. One takes a FileFilter - you can use that to filter your files:


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Pattern-based file/class searching
 
Similar Threads
Generating Dynamic XML using Reflection for Classes
Problem While Parsing XML
Runtime Creating Tables
Problem While Parsing Xml,Pls Advice A Solution
Does the identifier name have to be the same in all persistent classes ?