Reputation: 1994
I noticed that when I try to load a resource (an image, data, sound file, ect.) it is not possible to put it in the same file as the source code and just type "soundfiles/sound.wav". What is the best way to get this url?
Specifically here:
// load wave data from buffer
WaveData wavefile = WaveData.create("spaceinvaders/" + path);
I have done this before in many different ways, just wondering what the best way is.
Upvotes: 1
Views: 154
Reputation: 15434
If you ship your application in jar it's common way to package resources also in jar and access them using classloader:
//jar structure
your.jar
|--com
| `--... //classes here
`--resources
`--spaceinvaders
`--sound.wav
And code to access:
InputStream resource = getClass().getClassLoader().getResourceAsStream("resources/spaceinvaders/sound.wav");
Upvotes: 2