Loading images from a JAR

Hi,

My class is currently stored in a subdirectory of my JAR file, and in the directory with the class is a "textures" directory, containing all of my images.

When I run my class from the directory before I zip it up to be a JAR, it works fine. But, as soon as I run it as a JAR file, it crashes when loading the images.

Here's the code I'm using to load the images:

BufferedImage temp =null;

String path = this.getClass().getResource("textures/" + imagePath).toString();

temp = ImageIO.read(new File(new URI(path)));

What am I doing wrong?

Thanks for any assistance! =)

[752 byte] By [Hmmmmmma] at [2007-11-27 4:56:25]
# 1
check this URL http://www.rgagnon.com/javadetails/java-0240.html
AnanSmritia at 2007-7-12 10:11:34 > top of Java-index,Java Essentials,New To Java...
# 2
Why convert to and from a string? And once you put the images inside a .jar file they can no longer be accessed using a File. temp = ImageIO.read(getClass().getResource("textures/" + imagePath));
pbrockway2a at 2007-7-12 10:11:34 > top of Java-index,Java Essentials,New To Java...
# 3

Hiii bro ,

I think this will help u ,,,,,,,,

suppose you have a folder Image , under that folder there aresome image filesand you have a main class say TestMain.class .

In your main class(TestMain)

import javax.swing.ImageIcon;

Now write this code into your main class-->

public ImageIcon customOpenIcon = new ImageIcon(TestMain.class.getResource("/image/expanded.gif"));

Thanks,

sb

sb.majumder_07a at 2007-7-12 10:11:34 > top of Java-index,Java Essentials,New To Java...
# 4
For more information > http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/ImageIcon.html
sb.majumder_07a at 2007-7-12 10:11:34 > top of Java-index,Java Essentials,New To Java...