java.io.FilePermission - 拒绝访问

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5810298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 12:53:53  来源:igfitidea点击:

java.io.FilePermission - access denied

java

提问by athresh

Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: acc ess denied (java.io.FilePermission write)

线程“AWT-EventQueue-1”中的异常java.security.AccessControlException:访问被拒绝(java.io.FilePermission write)

i am getting the above error when i tried to write into a file.

当我尝试写入文件时出现上述错误。

what i need to do kindly help out...

我需要做什么请帮忙...

i am running an applet application...

我正在运行一个小程序应用程序...

回答by asgs

Applets are by default denied from accessing the client's file I/O. You need to sign your applet or edit the policy files.

默认情况下,Applet 被拒绝访问客户端的文件 I/O。您需要签署您的小程序或编辑策略文件

回答by alpian

As far as i know Applets cannot write to files as this would be a security violation. You can expressly grant the file-writing permission to the JVM to enable this but i think that would be a really bad idea because your users would be allowing you to write whatever you wanted to their disk via the web. Why does your applet want to write to a file?

据我所知,Applet 无法写入文件,因为这会违反安全性。您可以明确授予 JVM 文件写入权限以启用此功能,但我认为这将是一个非常糟糕的主意,因为您的用户将允许您通过 Web 将任何您想要的内容写入他们的磁盘。为什么您的小程序要写入文件?

回答by Anthony Accioly

Is your applet signed? Non signed applets can't access files. See here: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html

你的小程序签名了吗?未签名的小程序无法访问文件。请参阅此处:http: //java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html

回答by user7412746

Do like this:

这样做:

 fos=AccessController.doPrivileged(new PrivilegedAction()
    public  FileOutputStream run() {
      return new FileOutputStream(f1);
    }
  });

or edit file "java.policy" add permission java.io.FilePermission "<<ALL FILES>>", "read,write";

或编辑文件“ java.policy”添加权限java.io.FilePermission "<<ALL FILES>>", "read,write"