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

arsenal picture arsenal · May 4, 2012 · Viewed 118.5k times · Source
final File parentDir = new File("S:\\PDSPopulatingProgram");
parentDir.mkdir();
final String hash = "popupateData";
final String fileName = hash + ".txt";
final File file = new File(parentDir, fileName);
file.createNewFile(); // Creates file PDSPopulatingProgram/popupateData.txt

I am trying to create a file in a folder but I am getting exception as

java.security.AccessControlException: Access denied

I am working in windows environment. I can create a folder from the Windows Explorer, but not from the Java Code.

How can I resolve this issue?

Answer

Petey B picture Petey B · May 4, 2012

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