例如,如果我在小程序类中使用此代码,请在小程序沙箱中运行它
public void init() {
try {
class doInit implements PrivilegedExceptionAction {
public Object run() throws Exception{
File file = new File("/tmp/1.txt");
FileOutputStream fos = null;
fos = new FileOutputStream(file);
fos.write("hello world2".getBytes());
fos.close();
return null;
}
}
;
doInit di = new doInit();
AccessController.doPrivileged(di);
我知道它会失败并抛出安全异常。 但为什么?
File
和 FileOutputStream
位于核心 java API 中,但我无法使用 doPrivileged
获取权限?
最佳答案
对于小程序,您作为小程序的开发者无权授予或撤销权限。 它们由执行小程序的计算机上的安全设置和策略决定。 小程序的一项要求是由有效且可信的证书进行签名。
关于java - doPrivileged 和 java applet 沙箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17104038/