Hi guys,

I am writing a small application which needs to load some images, and other resources. I am currently trying to find the best way to package these resources in my application. I have looked at some examples, I but I have been having trouble understanding them, and many seem to be image limited.

Right now the way I want my program to work, is to have it load one of the randomly selected .zmap 's that exist in a folder. Unfortunately I don't know where in my files should be put in the file structure.

I've attached an image that should show you my current file structure, and the location of the class that is loading these files.

It is worth noting that this is a desktop application, which I hope to distribute through a .jar (I am using netbeans).

Please assist a programer new to java :)

Attachments Screen_shot_2010-11-08_at_10.42_.40_AM_.png 27.25 KB Screen_shot_2010-11-08_at_10.43_.00_AM_.png 21.89 KB

Hey buddy!

Okay, the best way to package your resources is to tuck them away into your project's path (as you have done), and use Class.getResource(). What it does is return a URL object, which points to the specified file within the package, whether it's an image, a text file, or even a ".zmap" file. In your example, you would use

URL url = getClass().getResource( "/DataObjects/hey.zmap" );

This URL can then be used to get a file stream or whatever you need to access the
contents of the file. Note that this will need to be in a try/catch block. The best trick to using this method is to build a "resource loader" class that does something sensible upon failure.

Comments
Thanks for the help with this. I appreciate it, as well as the quick response.

Alright - that sounds reasonable. Will the getResource always point to the source folder?

Alright - that sounds reasonable. Will the getResource always point to the source folder?

Yes, as long as you use the form getResource( "\..." ), you will always get a URL that points there :-) If you have any problems just get back to me.

This question has already been answered. Start a new discussion instead.