Solved

list all resources in a folder

Posted on 2006-06-15
5
263 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:pallosp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 16910673
Try


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


0
 
LVL 9

Author Comment

by:pallosp
ID: 16910894
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
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 16910977
>>
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16914954
:-)
0
 
LVL 9

Author Comment

by:pallosp
ID: 16915044
Negative answer is also an answer :)
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question