Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Searching for files of a specific type in jdk1.4

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22667
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taking a step back: why are you trying to do this?
 
Ronan Dowd
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic