gpt4 book ai didi

java - 无法让小程序读取文本文件

转载 作者:行者123 更新时间:2023-12-01 23:51:24 25 4
gpt4 key购买 nike

我尝试让我的 Java Applet 从我的文本文件中读取,但是当我在浏览器中运行该 applet 时,我没有足够的权限来读取该文件。我尝试过使用策略文件,但似乎无法让它们工作。

后来我尝试了

System.setProperty("java.security.policy", "*filelocation*");

但是我收到了这个错误

java.security.AccessControlException: access denied (java.util.PropertyPermission        java.security.policy write)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at BIT.init(BIT.java:35)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

我可以通过哪些方式让我的小程序在浏览器中运行?它在 Eclipse 的 applet 查看器中运行良好。

最佳答案

原因在 What Applets Can and Cannot Do 中指定。它明确规定:

Applets that are not signed are restricted to the security sandbox, and run only if the user accepts the applet. Applets that are signed by a certificate from a recognized certificate authority can either run only in the sandbox, or can request permission to run outside the sandbox. In either case, the user must accept the applet's security certificate, otherwise the applet is blocked from running.

后来它指出:

Sandbox applets cannot perform the following operations:

  • They cannot access client resources such as the local filesystem, executable files, system clipboard, and printers.
  • They cannot connect to or retrieve resources from any third party server (any server other than the server it originated from).
  • They cannot load native libraries.
  • They cannot change the SecurityManager.
  • They cannot create a ClassLoader.
  • They cannot read certain system properties. See System Properties for a list of forbidden system properties.

要了解如何签署 Applet,请查看此处:How to Sign Applets Using RSA-Signed Certificates

关于java - 无法让小程序读取文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16255472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com