list all resources in a folder

How can the resources be listed in a particular folder?
getClass().getResources("resources/images") returns only the url of the images folder, not the urls of the files inside. * is not accepted as wildcard.
LVL 9
pallospAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CEHJConnect With a Mentor Commented:
Try


File[] resources = new File(getClass().getResource("resources/images").toURI()).listFiles();


0
 
pallospAuthor Commented:
getClassLoader() is missing - it's my fault

The correct code is:
File[] resources = new File(getClass().getClassLoader().getResource("resources/images").toURI()).listFiles();

Can the resources be fetched if they are packed in a .jar file?
0
 
CEHJConnect With a Mentor Commented:
>>
The correct code is:
File[] resources = new File(getClass().getClassLoader().getResource("resources/images").toURI()).listFiles();
>>

That's not necessary - see
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getResource(java.lang.String)

>>Can the resources be fetched if they are packed in a .jar file?

No
0
 
CEHJCommented:
:-)
0
 
pallospAuthor Commented:
Negative answer is also an answer :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.