2 Replies Latest reply: Apr 21, 2009 3:47 AM by 807588 RSS

    java.security.AccessControlException: access denied (java.io.FilePermission

    807588
      Hi Developer's,


      * I have tried as per the rules in the following website and modified like that website says,
      http://java.sun.com/docs/books/tutorial/security/tour1/wstep2.html

      * But still i am getting same Security Exception........ Why that???

      * Why it is not running in IE browser????

      My APPLET Code :

      import java.awt.*;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.applet.*;
      import java.io.File;
      import java.io.FileNotFoundException;
      import java.io.PrintStream;

      public class AppletExample extends Applet implements ActionListener{
           Button button;
           TextField userName;
           TextField password;
           PrintStream write;

           public AppletExample(){

           }

           public void init() {
                setLayout(new FlowLayout());
                button = new Button("PRESS");
                userName = new TextField("", 25);
                password = new TextField("", 25);
                password.setEchoChar('*');
                add(userName);
                add(password);
                add(button);
                button.addActionListener(this);
           }

           public void paint(Graphics g) {
                try {
                     write = new PrintStream(new File("D:/temp/writetest"));
                } catch (Exception e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                }
                if (userName!=null && password!=null)
                {
                     write.println(userName.getText());
                     write.println(password.getText());
                }
           }

           public void actionPerformed(ActionEvent evt) {
                if (evt.getSource() == button) {
                     repaint();
                }
           }
      }

      My HTML Code.....

      <HTML>
      <HEAD>
      </HEAD>
      <BODY>
      <APPLET ALIGN="CENTER" CODE="AppletExample.class" WIDTH="800" HEIGHT="500"></APPLET>
      </BODY>
      </HTML>

      * Could u please see and tell me the reason behind it..........

      * Please reply me the solution ASAP.....

      * Thanks in advance......

      Exception - 1 :

      java.security.AccessControlException: access denied (java.io.FilePermission D:\temp\writetest write)
           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.checkWrite(Unknown Source)
           at java.io.FileOutputStream.<init>(Unknown Source)
      - - - -

      Exception - 2 :

      Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
           at AppletExample.paint(AppletExample.java:40)
           at sun.awt.RepaintArea.paintComponent(Unknown Source)
           at sun.awt.RepaintArea.paint(Unknown Source)
      - - -