gpt4 book ai didi

java - Java Applet 中的文件权限错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:18:14 25 4
gpt4 key购买 nike

我有一个Java小程序,需要使用一些文件夹来读取一些文件等。这些文件夹位于正确的位置,并且与index.html(运行小程序)位于同一目录中。这是 JApplet 吐出的错误:

java.lang.reflect.InvocationTargetException
at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(DeployAWTUtil.java:116)
at sun.plugin2.applet.Plugin2Manager.runOnEDT(Plugin2Manager.java:3541)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3072)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission ./results read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at java.io.File.list(File.java:971)
at java.io.File.listFiles(File.java:1129)
at WhoHasMore.JShellFrame.getDefaultResultsFileName(JShellFrame.java:453)
at WhoHasMore.JShellFrame.<init>(JShellFrame.java:28)
at WhoHasMore.<init>(WhoHasMore.java:23)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.plugin2.applet.Plugin2Manager$13.run(Plugin2Manager.java:3060)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:677)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:638)
at java.awt.EventQueue$1.run(EventQueue.java:636)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:647)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception: java.lang.reflect.InvocationTargetException

如您所见,错误似乎来自

Caused by: java.security.AccessControlException: access denied (java.io.FilePermission ./results read)

为什么从名为“results”的文件夹中读取数据的访问被拒绝?我该如何解决这个问题?

最佳答案

您尝试使用的方法 (java.io.File.listFiles) 无法通过 HTTP 运行。您需要选择另一种列出文件的方式,例如将文件列表放入已知 URL 的文本文件中并下载该文件,或者将其作为小程序 jarfile 的一部分。

关于java - Java Applet 中的文件权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10059921/

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