I have a javaapplet 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...
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.
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.
Joined: May 13, 2009
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.