gpt4 book ai didi

java - 列出已签名小程序的本地目录

转载 作者:行者123 更新时间:2023-12-01 06:00:07 25 4
gpt4 key购买 nike

以下小程序被编译并打包到 jar 中,然后使用自签名证书进行签名。

import java.applet.Applet;
import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;

public class Test extends Applet {
private static final long serialVersionUID = -3127185193501384816L;

private final class DirectoryLister implements PrivilegedAction<File[]> {
private final String attachmentsFolder;

private DirectoryLister(String attachmentsFolder) {
this.attachmentsFolder = attachmentsFolder;
}

public File[] run() {
return new File(attachmentsFolder).listFiles();
}
}

public File[] getFiles() throws PrivilegedActionException {
String attachmentsFolder = getParameter("attachmentsFolder");

if (attachmentsFolder != null) {
return AccessController.doPrivileged(new DirectoryLister(
attachmentsFolder));
}

return null;
}
}

Applet实例化如下:

<applet id="applet"
code="Test"
archive="applet.jar">
<param name="attachmentsFolder"
value="c:/test" />
</applet>

小程序的使用方法如下:

var files = applet.getFiles();

for (var file in files) {
// Do something to file.
}

FF。遇到错误:

java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation.CallMethod(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(Unknown Source)
... 4 more
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission c:\test 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.list(Unknown Source)
at java.io.File.listFiles(Unknown Source)
at Test$DirectoryLister.run(Test.java:20)
at Test$DirectoryLister.run(Test.java:1)
at java.security.AccessController.doPrivileged(Native Method)
at Test.getFiles(Test.java:28)
... 14 more

这让我问我是否仍然需要在 Java 主目录中的配置文件之一中显式授予权限才能读取 c:/test?如果是这样,有人能给我指点如何执行此操作的指南吗?

最佳答案

显然是缓存问题。清除所有缓存并重新构建/重新部署解决了问题。即,不需要额外的权限设置。

关于java - 列出已签名小程序的本地目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/963354/

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