Two Laptop Bag
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 Elasticsearch in Action this week in the Big Data 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: 19351
    
  10

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.
 
Consider Paul's rocket mass heater.
 
subject: Listing files embedded in an EAR