0

I have a Java applet which I am trying to run within an HTML file using HTML applet tag <applet>, but it is throwing the following exception:

Caused by: java.security.AccessControlException: access denied 
    (java.io.FilePermission darkorange.png read)

Oracle site has explained giving access to applets using policy like:

appletviewer -J-Djava.security.policy=applet 

http://docs.oracle.com/javase/tutorial/security/tour1/examples/WriteFile.html

But that is only in DOS, how do I make my browser recognize the security file?

Roman C
  • 49,761
  • 33
  • 66
  • 176
user930412
  • 11
  • 5
  • What is `darkorange.png`? Is it an image used by the app. itself? – Andrew Thompson Dec 25 '11 at 20:08
  • yes it is an image used by the program.the applet works fine in eclipse , but in browser it gives this exception , i know it can be done as amazon s3 use a java applet to load files from client machine to server, just uable to figure out how – user930412 Dec 26 '11 at 05:51

1 Answers1

0

Applets cannot read/write files from local machine and/or connect/read/write from/to a domain different from the one it was loaded from. They are restricted to a sandbox-like environment and need permission to access system resources outside their restricted environment. Applets are restricted to read operations within their local directory. All other access operations require permission. I would suggest to revisit your requirement of reading a file from a client machine as this is apparently isn't a valid requirement.

BTW, if you need to do it anyways, then your applet jars has to be signed and relevant permissions should be granted to your applet in the user java.policy file on the client machine. Refer to the java documentation for specifying the policy.

Drona
  • 6,886
  • 1
  • 29
  • 35
  • Hi finally after three days i have solved it , there are two parts to the problem. one is two place code which access files on client machines inside doprivileged method, second is to sign the jar http://www.raditha.com/java/sandbox/unsigned.php This page did the rescue – user930412 Dec 28 '11 at 08:22