解决java.security.AccessControlException的快速方法
我有一个小程序,它必须从服务器读取文件。 但我收到以下异常,
java.security.AccessControlException: access denied (java.io.FilePermission \kb1.xml read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.isDirectory(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
...
我尝试将 java.policy.applet 文件放入授予读取权限的文件,但它不起作用。 我需要一个快速的方法来解决这个问题。 我必须指定,为了制作这个小程序,我使用了 java 6。
I have an applet which have to read a file from server. But I receive the following exception
java.security.AccessControlException: access denied (java.io.FilePermission \kb1.xml read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.isDirectory(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
...
I tried to put a java.policy.applet file with permission granted for reading but it doesn't work.
I need a quick way to solve this problem. I have to specify that for making this applet I used java 6.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您说您想读取服务器上的文件,但异常是由于尝试读取客户端(运行小程序的计算机)上的文件而引起的。
您无法直接从服务器读取文件。 您需要通过 HTTP 访问它们,或者将它们放入小程序的 jar 文件中并从那里加载。
You said you want to read a file on the server, but the exception is caused by trying to read a file on the client (the machine that is running the applet).
You cannot read files from the server directly. You need to access them via HTTP or put them into the applet's jar file and load it from there.