This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes Listing files embedded in an EAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Listing files embedded in an EAR" Watch "Listing files embedded in an EAR" New topic
Author

Listing files embedded in an EAR

vince walker
Greenhorn

Joined: Aug 30, 2013
Posts: 1
I have XML files which I want to store in an EAR. When the app starts, I want to read all the XML files and load them into memory. I found getClass().getResourceAsStream(...) to load a file if I know the name. But how can I list all the files and iterate through them if I don't know the names in advance?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Store a text file along with the XML files which contains a list of the names of the XML files.
Balaji Manoharan Bm
Greenhorn

Joined: Sep 22, 2013
Posts: 13
Give the directory name as input to getResourceAsStream() and the use File.listFiles() method to know all the files available in that directory.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Listing files embedded in an EAR