简体   繁体   English

如何处理java.security.AccessControlException

[英]How to handle java.security.AccessControlException

I'm trying to launch my applet locally and this is the exception I get: 我正在尝试在本地启动小程序,这是我得到的例外:
I don't know why this is happening the mp3 is already located on the jar file, why can't I access it? 我不知道为什么会这样,mp3已经位于jar文件中,为什么我不能访问它?

SEVERE: null
java.security.AccessControlException: access denied (java.io.FilePermission file:\C:\applet\CairoNightTrainClient.jar!\Music\train.mp3 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.FileInputStream.<init>(Unknown Source)
    at com.sun.media.codec.audio.mp3.JS_MP3FileReader.getAudioInputStream(JS_MP3FileReader.java:113)
    at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
    at LogicEngine.DJ.createClip(DJ.java:56)
    at LogicEngine.DJ.<init>(DJ.java:42)
    at GUI.JPanelGameApplet$1.run(JPanelGameApplet.java:65)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

Applets (or at least untrusted applets) are not allowed to access the local file system. 小应用程序(或至少不受信任的小应用程序)不允许访问本地文件系统。 This is kind of a good thing as most people might get upset if random websites had such access. 这是一件好事,因为如果随机网站具有大多数访问权限,大多数人可能会感到沮丧。

If you want to access a file go through javax.jnlp (just google it) and it'll provide an API that presents the user with a file chooser to allow applets to read a specific file of their choosing. 如果您想访问文件,请通过javax.jnlp (只需在Google上进行搜索),它将提供一个API,向用户提供文件选择器,以允许applet读取他们选择的特定文件。

If it's just a file that is part of the applet, use either a resource ( Class.getResourceAsStream ) or through an http connection ( URL ) 如果它只是applet的一部分,请使用资源( Class.getResourceAsStream )或通过http连接( URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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