User48591
User48591

Reputation: 301

How to get list of resource files?

I am able to read a particular resource into an InputStream.

InputStream inputStream = MyClass.getResourceAsStream("/resources/test.xml")

But I cannot get a list of all resource files in the resources package for some reason.

I have tried the code from this answer to no avail.

Edit: I am only interested in getting a list of the file names from the resources package.

Edit 2: The code is called from a runtime eclipse instance.

Upvotes: 1

Views: 180

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168815

Most of the answers to this question presume that the resource is being found as a 'loose' (not in a Jar) file on the local file system. But once deployed, those types of things will likely be inside a Jar and any use of the File class will fail to act as a file (because it's not).

To get a listing from inside a Jar, insert a textual list into the Jar at build time that lists each other resource of interest. At runtime, load the list, then proceed from there.

Upvotes: 2

Related Questions