Access Control Exception: access denied( "java.io.FilePermission" "[image]" "read")

10,069

This is because Applets need permissions to read/write from/to files. Maybe this page can help you: How Can An Applet Read Files On The Local File System

Share:
10,069

Related videos on Youtube

Andreea
Author by

Andreea

Updated on May 25, 2022

Comments

  • Andreea
    Andreea almost 2 years

    I'm on my first week using Java. I don't know very much about applets, and I'm trying to learn more using a book. I've already done some applets that contain simple animation, but when I tried drawing an image I've got stock on this:

    access denied( "java.io.FilePermission" "[image]" "read").

    Anyone who can help me?

        import java.awt.Graphics;
        import java.awt.Image;
    
        public class Wave extends java.applet.Applet{
    
            Image waveimg;
    
            public void init(){
    
                waveimg=getImage(getCodeBase(),"wave.jpg");
    
            }
    
            public void paint(Graphics g){
    
                g.drawImage(waveimg, 10,10,this);
    
            }
      }
    
    • npinti
      npinti almost 9 years
      Most likely, the applet or its container does not have permission to read from the provided URL. See if you can get to draw an image available through a publicly accessible URL.
    • Kami
      Kami almost 9 years
      @Andreea if one of the Answers solved your problem, then please select one to close this question :)
    • Andrew Thompson
      Andrew Thompson almost 9 years
      1) Why code an applet? If it is due to the teacher specifying it, please refer them to Why CS teachers should stop teaching Java applets. 2) Why use AWT? See this answer for many good reasons to abandon AWT using components in favor of Swing.
    • Andrew Thompson
      Andrew Thompson almost 9 years
      access denied( "java.io.FilePermission" "[image]" "read"). How are you loading the applet? Using applet viewer? Using the some HTML loaded off the local file system in the default browser? Using some HTML loaded off a local server in the default browser? This information might make all the difference about when the applet will succeed or fail.
  • Andrew Thompson
    Andrew Thompson almost 9 years
    "Applets need permissions to read/write from/to files." Not to load files, or at least, not when loading them from the same site using getImage(getCodeBase(),..);