Use the getResourceAsStream method
import java.awt.Image;
import java.awt.Toolkit;
import java.io.BufferedInputStream;
import java.io.InputStream;
public class Main {
public static void main(String[] argv) throws Exception {
InputStream is = Main.class.getResourceAsStream("image.gif");
BufferedInputStream bis = new BufferedInputStream(is);
byte[] byBuf = new byte[10000];
int byteRead = bis.read(byBuf, 0, 10000);
Image img = Toolkit.getDefaultToolkit().createImage(byBuf);
}
}
Related examples in the same category