在的AccessControlException的Java Applet [英] AccessControlException in Java Applet

查看:150
本文介绍了在的AccessControlException的Java Applet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个小程序的网页内,但每当我运行它,我得到这样的:

I have created an applet within a web page, but whenever I run it, I get this:

Exception in thread "Thread-13" java.security.AccessControlException: access denied ("java.io.FilePermission" "defensebg.png" "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.canRead(Unknown Source)
    at javax.imageio.ImageIO.read(Unknown Source)
    at Defense.run(Defense.java:63)
    at java.lang.Thread.run(Unknown Source)

我该如何解决这个问题?

How do I fix this?

推荐答案

因为我知道一些关于你的小程序,并深信这些图像是应用的一个固有部分,我会采取不同的策略来paulms4。

Since I know a little about your applet and am convinced these images are an inherent part of the application, I will take a different tack to paulms4.

忘记文件实例。他们既不是可行的这一点,也没有必要。只有受信任的小程序可以访问文件,但即使这样,这一个applet可以建立唯一的地方,一个文件是一个指向用户的PC的文件系统上的位置。显然,对于您的小程序的图像是不可用这种方式(OK - 他们可能是在浏览器缓存,但就是没有用的,我们的)

Forget the File instances. They are neither workable for this, nor necessary. Only a trusted applet can access a File, but even then, the only place that an applet can establish a File is one that points to locations on the file-system of the user's PC. Obviously the images for your applet are not available that way (OK - they might be in a browser cache, but that is no use to us).

这将是更典型(安培;更容易)通过网​​址来访问applet的资源。一个URL可以相对于$ C $的c-碱或小程序的文档碱来建立。如果图像实际上是一个JAR中,他们成为一个嵌入的资源 - 看到的信息。页面至于如何获得一个网址。

It would be more typical (& easier) to access applet resource by URL. An URL can be established relative to the code-base or document-base of the applet. If the images are actually inside a Jar, they become an embedded resource - see the info. page as to how to gain an URL.

大多数的J2SE的加载一个只读的资源会接受的方法文件网​​址的InputStream 。我使用的URL经常为它的通用工具。一个URL可以重新present网络资源,本地文件系统中的文件,或深埋一个jar文件(不论网络或本地文件系统)。

Most of the methods in the J2SE that load a 'read only' resource will accept File, URL or InputStream. I use URL most often for the generic utility of it. An URL can represent a web resource, a file on the local file system, or a resource buried deep inside a Jar file (whether or on the web or the local file-system).

这篇关于在的AccessControlException的Java Applet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆