Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issues with Jar Files and loading images

 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java applet on my desktop PC. The htm file that loads the applet, the applet class files, and some image files (png formt) are all in the same directory. The image files are loaded by the following method...

ImageIO.read(new File("wk.png"))

which creates a BufferedImage object. This all works flawlessly.

Question #1. I know there are security restrictions regarding applet access to the local file system. So it is not quite clear why I can do this when applets are supposed to be restricted from accessing the local file system.

Question #2. When I create a jar file using jar cvf fchess.jar * I can see that the class files and image files get added to the jar file, and when I edit my Applet tags to use the jar file everything works fine, until I remove the png files from the directory. So it follows that when you use ImageIO to load the files, it looks to the file system regardless of whether or not the image files are packed in the jar file. The problem is, I can't find another way to create BufferedImage objects from external image files.

Anyways, If someone could point me in the right direction I would be grateful.

Thanks.
 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no clue what is that ImageIO, but I can suggest you to use Classe's getResourceAsStream method to retrieve data from your jar's resources and then create your BufferedImages based on these data.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zandis Murāns wrote:I have no clue what is that ImageIO, but I can suggest you to use Classe's getResourceAsStream method to retrieve data from your jar's resources and then create your BufferedImages based on these data.


OK, I can see that your getResourcesAsStream method would return an InputStream object. And I can see that class ImageIO, which is in the Sun API docs, has a read method that works with an InputStream rather than directly with a file resource, so I'll be pursuing that angle, will let you know how it goes.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic