如何处理java.security.AccessControlException

时间:2011-10-21 11:39:54

标签: java exception applet mp3

我正在尝试在本地启动我的applet,这是我得到的例外:
我不知道为什么会发生这种情况,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)

1 个答案:

答案 0 :(得分:1)

不允许Applet(或至少不受信任的applet)访问本地文件系统。这是一件好事,因为如果随机网站有这样的访问权限,大多数人可能会感到不安。

如果你想访问一个文件请浏览javax.jnlp(只是google),它会提供一个API,向用户提供一个文件选择器,以允许applet读取他们选择的特定文件。 / p>

如果它只是属于applet的文件,请使用资源(Class.getResourceAsStream)或通过http连接(URL