Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Posts
    433
    Thanks
    3
    Thanked 0 Times in 0 Posts

    trying to read file...

    String theName=getParameter("name");
    if (theName==null)
    theName="default.txt";
    try {

    FileReader look= new FileReader(theName);
    BufferedReader buff = new BufferedReader(look);
    boolean eof=false;
    while(!eof){
    theString=buff.readLine();
    if (theString==null)
    eof=true;
    }
    look.close();
    }
    catch(IOException e){
    System.out.println("File does not exist " + e.toString());
    }
    }



    This code returns the no error at all at compile-time but these run-time errors


    java.security.AccessControlException: access denied (java.io.FilePermission default.txt read)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
    at java.security.AccessController.checkPermission(AccessController.java:401)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
    at java.lang.SecurityManager.checkRead(SecurityManager.java:887)
    at java.io.FileInputStream.<init>(FileInputStream.java:100)
    at java.io.FileInputStream.<init>(FileInputStream.java:66)
    at java.io.FileReader.<init>(FileReader.java:39)
    at Package.exercise2.init(exercise2.java:49)
    at sun.applet.AppletPanel.run(AppletPanel.java:341)
    at java.lang.Thread.run(Thread.java:536)
    
    Suggestion?

  • #2
    New Coder
    Join Date
    Apr 2004
    Location
    Texas
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First, check file permissions on file make sure you can read it....
    then
    You might need to change your security.policy file. So that it reflects IO
    permission for your class

    something like
    grant {
    permission java.io.FilePermission "C:\\test\\default.txt", "read";
    };

    read all about it here....
    http://java.sun.com/j2se/1.4.2/docs/...licyFiles.html
    Jason B


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •