Question

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.

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top