This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Searching for files of a specific type in jdk1.4 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 "Searching for files of a specific type in jdk1.4" Watch "Searching for files of a specific type in jdk1.4" New topic
Author

Searching for files of a specific type in jdk1.4

Ronan Dowd
Ranch Hand

Joined: Jan 21, 2006
Posts: 84
Am using jdk1.6 and want to find an easy way, from within a JUnit test, to locate files in my project of a specific type
I want my test to find all files that end with "hbm.xml" and once i have a list of the files, to then
read their contents.

I can do the below individually for one file but I've to specify it's path:

String fileContents = org.apache.commons.io.FileUtils.readFileToString("src/main/resources/com/boreas/model/Customer.hbm.xml")

I don't want to have to update my test if a user adds a new hbm.xml file. I'm sure theres some way of doing this in java.
Any help would be great.
Cheers. Ro.


SCJP 1.4 | OCWCD JEE 5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Check out File.listFiles(FileFilter) or File.listFiles(FilenameFilter). The former is probably better because that one allows you to list folders as well, so you can check the folder recursively. In code, with a few gaps:


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Taking a step back: why are you trying to do this?
Ronan Dowd
Ranch Hand

Joined: Jan 21, 2006
Posts: 84
Hi, am using hibernate in my application and want to, as part of a JUnit test, execute all named queries that i've defined. In hibernate, named queries are defined in files
ending in "hbm.xml" so I want to find all files in my application with this file ending then I'm going to use the java Matcher and Pattern classes to
find, in each "hbm.xml" file the name of the query. The i'm going to execute each query. I tried to see if there was a way in hibernate to get all named queries which you've
defined but there doesn't appear to be. Hence me going the java route of finding the file and parsing the contents..
Ro.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not sure if that makes any sense to me: it doesn't test that the named queries you actually *need* are there, that would have to be done on a query-by-query basis, by code that knows (a) what the query is named, and (b) what the query is supposed to return.

I'm just not really sure what you're testing doing what you want to do is all.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Searching for files of a specific type in jdk1.4
 
Similar Threads
Mappings and POJO's in different folders
SchemaExportTask query
Any way to access the Hibernate mapping files from the persistence objects?
unable to create War using Ant
changing the database name