If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

how to list resources in a package?

I have a set of files (a.txt, b.txt, c.txt, ....) in a java package along with code. I can access one of these using the getResourceAsStream method. However, I want to get a list of these resources, using a regular expression to find all resources that satisfy *.txt

This needs to work whether the .class and *.txt files are on disk or in a jar file.

Seems like something the reflection api or the Package api should do, but I can't find a way.

You could scan the jar file(s) using the methods available in java.util.jar/java.util.zip, and, for the case of plain files, directory scanning using the methods in the File class. Both cases would use regex to identify the desired files.