Console don't let my applet run because of a file

回眸只為那壹抹淺笑 提交于 2019-12-11 09:02:15

问题


I am working in an applet. It works perfect with Eclipse but when I try to run from Console it gives me this stack trace:

C:\Course Technology\src>appletviewer TestJAlienHunt.html

Path for file entered D:\Course Technology\AssignmentFinal\scoreFile.txt java.security.AccessControlException: access denied ("java.io.FilePermission" "D:\Course Technology\AssignmentFinal\scoreFile.txt" "read")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
    at java.security.AccessController.checkPermission(AccessController.java:555)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
    at sun.nio.fs.WindowsPath.checkRead(WindowsPath.java:792)
    at sun.nio.fs.WindowsFileSystemProvider.checkAccess(WindowsFileSystemProvider.java:360)
    at java.nio.file.Files.exists(Files.java:2311)
    at ReadFile.fileExists(ReadFile.java:47)
    at JAlienHunt.readScore(JAlienHunt.java:187)
    at JAlienHunt.init(JAlienHunt.java:73)
    at sun.applet.AppletPanel.run(AppletPanel.java:434)
    at java.lang.Thread.run(Thread.java:722)

The file has permission to read and write, why I am getting this?


回答1:


An applet needs to be digitally signed by you and trusted by the end user before it can access the local file system on the user's computer.

I highlight user's computer because that is where any File will equate to. There is no option for getting a File pointing to the server. If this is read only and the server hosts the resource, access it by URL.



来源:https://stackoverflow.com/questions/16096508/console-dont-let-my-applet-run-because-of-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!