Search code examples
javaappletpolicysql-grant

Granting permission for Java Applet to write to system


I need to grant my applet the ability to save to a file. I tried to make a java.policy file to accomplish this and it's not working. Below is the code for the policy file and for the method that saves to the data file.

public void save()
{
    try
    {
        out = new BufferedWriter(new FileWriter("_stats.dat"));
        for (int i = 0; i < a.length; i++)
        {
            out.write(a[i].trim());
            out.newLine();
        }
        out.close();
    }
    catch (FileNotFoundException f)
    {
        System.out.println(f.getMessage());
    }
    catch (IOException i)
    {
        System.out.println(i.getMessage());
    }
}

grant {
    permission java.io.FilePermission "<<ALL FILES>>", "write";
};

They are both in the same directory and it appears that the save method is not recognizing the policy file or something. Thanks in advance for your feedback.


Solution

  • You might want to have a look at this previous post:

    How to write to a file in applets in java?

    Make sure your applet is signed.