【问题标题】:permissions in applet Exception小程序异常中的权限
【发布时间】:2014-01-04 22:17:59
【问题描述】:

我有一个在客户端读取文件的小程序。

public class MyApplet extends Applet {
     public static void main(String[] args){
          JFrame frame = new JFrame();
          MyApplet inst = new MyApplet();
          frame.getContentPane().add(inst);
          ((JComponent)frame.getContentPane()).setPreferredSize(inst.getSize());
          frame.pack();
          frame.setVisible(true);
     }
     public MyApplet(){
          initGUI();
     }
     public String readFile() { 
          String thisLine, ret = ""; 
          String fn="c:\\1\\a.txt";
          try { 
            FileInputStream fin =  new FileInputStream(fn); 
            BufferedReader myInput = new BufferedReader (new InputStreamReader(fin));
            while ((thisLine = myInput.readLine()) != null) {  
                ret += thisLine + "\n";
            } 
          } catch (Exception e) {
            ret = e.toString();
          } 
        return ret;
    }
} 

我遇到的异常

java.security.AccessControlException: access denied ("java.io.FilePermission" "c:\1\a.txt" "read")

请帮帮我 我签了小程序

【问题讨论】:

    标签: java permissions applet


    【解决方案1】:

    Oracle 的官方 Java 文档包含有关它的信息。

    http://docs.oracle.com/javase/tutorial/security/tour1/wstep2.html

    请注意,小程序通常被认为不太安全,因此可能会出现许多问题(不仅是权限管理,还有某些浏览器等),尤其是在尝试访问文件时。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-07
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      相关资源
      最近更新 更多