Use the getResourceAsStream method : Toolkit « Development Class « Java






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

1.Check Desktop Property by using the Toolkit.getDefaultToolkit()
2.Getting the Screen Size
3.Centering a Frame, Window, or Dialog on the Screen
4.Environment information.