Solved

list all resources in a folder

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now