How to Get Image from file

Alex Nicolaou anicolao at
Tue Jan 26 11:11:06 PST 1999

Archie Cobbs wrote:
> John C. Hayward writes:
> > Dear Kaffe users,
> >    Please excuse this a bit off topic query but this group probably
> > has the answer.
> >
> >    In the applet class of java there is a getImage method for obtaining
> > a Image from a URL.  I would like to get an Image from a local file
> > in a non applet application.  What is the best way to do so?
> Isn't something like "file:/home/user/foo.gif" also considered an URL?

Yes, it is, but the original question was about getting an image from an
application, so he doesn't have an Applet instance to call getImage on,
and Applet.getImage isn't static.

You can use Toolkit.getImage(String filename) to get the image in an
application, but the API shows its age by not taking a File instance and
is not portable to applets. 

The "officially sanctioned" way to do this is described in your API
documentation or on the Java WWW site at
(it's the second-last link on the JDK documentation page if you've
downloaded the docs for 1.1.X). The basic jist of the method is "stick
all your images in a JAR file and let Java find them for you". Amongst
other advantages, bundling up the images cleans up the look of how your
application installs, speeds your applet's download, and works for both
applets and applications. 


More information about the kaffe mailing list