?
Solved

list all resources in a folder

Posted on 2006-06-15
5
Medium Priority
?
269 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 1000 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 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