Background:
One thing that I do a fair amount in my programs, is load resources, such as images, or text files. However, I have yet to find an elegant way of doing it. The method I have decided on is to obtain a java.io.File object that represents the directory I want to work from, this will usually be either the directory containing my class files, a "resources" sub-directory, or something similar. I then create a new File object from this one that represents the file I want. I find this works better than calling getClass().getResource(name), because it allows you to get paths for files that don't yet exist.
In it's simplest form, my getThisDirectory() method is nice and elegant, and works well.
The problem is that once you start trying to deal with classes that are either members of a package other than the unnamed package, or packaged in a jar file (or even both), this method becomes very messy, and is probably not at all portable.
The challenge:
Find a better way of achieving my goal.
The prize:
My eternal gratitude. What's that you say? That's not enough? Oh dear, it doesn't look like I will be getting much help then
.
The existing method:
You can see working examples of my code in the net.skinnybrown.utils.ResourceFinder class, and in the ReDecorator program.
Here is the code used in the ReDecorator program, this version works from within jar files, the ResourceFinder version is simpler, but more robust (I think):
Anybody who thinks they have a better way of doing this, or at least knows of a situation where this won't work, please email me at the address below, you will make me truely happy
.

