简体   繁体   中英

Java applet giving AccessControlException

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM