Trying to load icon from jar file

后端 未结 6 1998
时光说笑
时光说笑 2020-12-10 14:49

I am trying to load icons from a jar file. I have both tried to load it from classes within the jar file as well as classes outside the jar file.

outside of the

6条回答
  •  [愿得一人]
    2020-12-10 15:21

    Skip the class loader, and get the resource as a stream instead. If you don't need the URL you can turn them directly into BufferedImages like so. I've left the stream and exception handling as a further exercise.

    InputStream stream = LoadHTMLExample.class
        .getResourceAsStream( "/icons/mouse.png" );
    BufferedImage image = ImageIO.read( stream );
    

    Questioner needs the URL which brings us back to everyone else's suggestions. The images are definitely in the jar aren't they?

提交回复
热议问题