I am rewriting my classes that loads resources inside of my game. My professor told us to try not to use "/" slash sign in our Strings/File/URL when loading our resources. I am using Classname.class.getResource(someString)
to get URLs so I can load my resources which works great ( see code below). I read the Oracle Docs for class.getResource()
and there I have to use "/"
. I would like to know if there's a better way for loading resources (images and audio files mostly) than using ClassName.class.getResource()
? I don't have any speed or memory requirements. Here an example of how I load an BufferedImage
.
try {
// Example path = "/menu/background2.png"
sourceImage = ImageIO.read(ResourceManager.class.getResource(path));
} catch (IOException e) {
System.out.println("Failed to load: " + path);
e.printStackTrace();
}