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

前端 未结 3 1849
傲寒
傲寒 2020-11-29 10:22
final File parentDir = new File(\"S:\\\\PDSPopulatingProgram\");
parentDir.mkdir();
final String hash = \"popupateData\";
final String fileName = hash + \".txt\";
fi         


        
相关标签:
3条回答
  • 2020-11-29 10:26

    Within your <jre location>\lib\security\java.policy try adding:

    grant { permission java.security.AllPermission; };

    And see if it allows you. If so, you will have to add more granular permissions.

    See:

    Java 8 Documentation for java.policy files

    and

    http://java.sun.com/developer/onlineTraining/Programming/JDCBook/appA.html

    0 讨论(0)
  • 2020-11-29 10:43

    Just document it here on Windows you need to escape the \ character:

    "e:\\directory\\-"
    
    0 讨论(0)
  • 2020-11-29 10:44

    Although it is not recommended, but if you really want to let your web application access a folder outside its deployment directory. You need to add following permission in java.policy file (path is as in the reply of Petey B)

    permission java.io.FilePermission "your folder path", "write"
    

    In your case it would be

    permission java.io.FilePermission "S:/PDSPopulatingProgram/-", "write"
    

    Here /- means any files or sub-folders inside this folder.

    Warning: But by doing this, you are inviting some security risk.

    0 讨论(0)
提交回复
热议问题