Loading Images
Hello, I'm using NetBeans and trying to utilize Image Icons in my program. I am using the example code Sun provided in their Image Icon example program to load the images:
protectedstatic ImageIcon createAppImageIcon(String path)
{
int MAX_IMAGE_SIZE = 124000;// Change this to the size of
// your biggest image, in bytes
int count = 0;
BufferedInputStream imgStream =new BufferedInputStream(
Test.class.getResourceAsStream(path));
if (imgStream !=null){
byte buf[] =newbyte[MAX_IMAGE_SIZE];
try{
count = imgStream.read(buf);
}catch (IOException ieo){
System.err.println("Couldn't read stream from file: " + path);
}
try{
imgStream.close();
}catch (IOException ieo){
System.err.println("Can't close file " + path);
}
if (count <= 0){
System.err.println("Empty file: " + path);
returnnull;
}
returnnew ImageIcon(Toolkit.getDefaultToolkit().createImage(buf));
}else{
System.err.println("Couldn't find file: " + path);
returnnull;
}
}
This works perfectly when I'm simply compiling and running the program from the IDE (or any other compiler for that matter) however as soon as I make it into a Jar and attempt to run it from command prompt I begin to get errors. Namely I get the "Couldn't read stream from file" and "Empty file" errors. I assume it has something to do with including certain directories or something, but I can't for the life of me get it to work. I've tried creating Jars with NetBeans and JGrasp with the same outcome. I can find the files fine enough and even list them using the list() method, however no images will show up. Thanks for you help, I'm sure it's just something little I overlooked, it always seems to be.

