• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pattern-based file/class searching  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 21136
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File has two method called listFiles. One takes a FileFilter - you can use that to filter your files:
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!