2

I got the following error while i was trying to read a file and store it's data into my applet(Java) i think that the main error is this :

java.security.AccessControlException: access denied (
     "java.io.FilePermission" "MyFile.txt" "read")

And I have no idea how to resolve it, thought it might something to add to my java.policy.applet file which include:

grant {
  permission java.security.AllPermission;
};

I also tried to google it but nothing works.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
xsss
  • 81
  • 1
  • 2
  • 9
  • 1
    Don't use AllPermissions, that's a massive security hole. Applets run within a strict security sandbox, that's the point. Why are y using an applet to do this? – MadProgrammer Sep 10 '14 at 21:01

1 Answers1

2

Thanks for the comments guys,

i have solved this problem by reading "MyFile.txt" as a URL, and then read it

the code:

        URL myURL = new URL("http://MyDomainName.com/MyFile.txt");
        BufferedReader in = new BufferedReader(
                new InputStreamReader(myURL.openStream()));

                String inputLine;
                while ((inputLine = in.readLine()) != null)
                    line.add(inputLine);
                in.close();

Solved

xsss
  • 81
  • 1
  • 2
  • 9
  • Safer and more portable to use something like `URL myURL = new URL(getDocumentBase(), "MyFile.txt");` ..glad you got it sorted. :) – Andrew Thompson Sep 12 '14 at 05:39