从签名的 Java 小程序中删除文件 [英] Deleting files from signed java applet
问题描述
当他退出应用程序时,我必须从用户系统中删除一些临时文件.该应用程序有小程序.小程序jar 已签名.我遵循调用applet 的destroy 方法来删除文件的策略.我正在通过 javascript 调用小程序的销毁方法像 document.myApplet.destroy() .调用此后,我在浏览器上收到错误
I have to delete some temporary file from a users system when he logs out of application. The application has applet. The applet jar is signed. I am following the strategy to call the applet's destroy method to delete files. I am invoking the destroy method of applet by javascript like document.myApplet.destroy() . After invoking this I am getting the error on browser as
未捕获的错误:java.security.AccessControlException:访问被拒绝(java.io.FilePermission 未捕获的错误:在 NPObject 上调用方法时出错.
推荐答案
好的,我自己得到了答案:参考此链接后 http://docs.oracle.com/javase/7/docs/api/java/security/AccessController.html ,我想通了,读取、写入甚至删除都可以通过将它们封装在 AccessController.doPrivileged 方法中来完成.
Ok I got the answer myself: After refering to this link http://docs.oracle.com/javase/7/docs/api/java/security/AccessController.html , I figured out ,that reading,writing or even deleting can be done by wraping them up in AccessController.doPrivileged method.
AccessController.doPrivileged(new PrivilegedAction() {
@Override
public Object run() {
try {
deleteAppCacheDirectory();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
});
这篇关于从签名的 Java 小程序中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!