Solved

list all resources in a folder

Posted on 2006-06-15
5
260 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jdbc error in jsp application 20 88
jsp login check 12 64
Find out all repos that a user is most active on Github 1 57
Tomcat 9 + java 8 error while trying to deploy a war file 2 850
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

734 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