Search code examples
javaswingjpaneljava-iojapplet

Why is there a file permission error?


I am getting a file permmission error when I use my Java applet on my website. The error is:

access denied ("java.io.FilePermision""image.png""read")

Solution

  • An applet operates in a restricted environment (known as a security sandbox) and,unless it is signed, can only load resources from the same location from where it was loaded. The images can be included in the applet jar file. To access these, you could use

    Image image = ImageIO.read(MyApplet.class.getResourceAsStream("/images/image.png"));