[Solved] Loadings resources images/sound relatively (?)

TL;DR

Hello

I was able to load images fine locally, and I’ve now tapped into an Applet and am attempting, through a SwingWorker, to load images relatively to my classpath. Now this is all fine if I know exactly what the fileName is. But what If I would like to load ALL the files in a folder. That is, how can I get a list of fileNames in a folder relatively? Locally, or with the File class, you can do it with File.listFiles() iirc - however this works only for absolute paths. Is there a simliar one for relative paths?

I’ve tried looking at ClassLoader and Class for methods but come up short.

Any ideas?

I’m kinda new to Java myself, but in my Applet I do something like this:


URL imgPath;
Image mySprite;
imgPath = getClass().getResource("images/");
mySprite = getImage(imgPath, "mysprite.png");

I use Eclipse. The images folder is in workspace/project/bin/ (you will need to create it).
I haven’t tried to pack everything into a .jar file yet to see if it still works when “deployed”.

Hmm, yes. Giving it a second thought is there any real need to load EVERYTHING from a folder? Not really come to think of it. I was thinking of loading all *.png images into a hashmap at the start and the distribute it from there to my objects. But since my specific classes have their own sprite_name, I can just use that to get a hold of the file. No need to laod everything from a folder, just the ones that are needed.