title: Issue with checking permission of a folder in java
body: <p>I am creating simple function to check weather I have write/delete permission to a folder</p>
  
  <p><strong>I want to know whether the operating system will allow writing into the folder or not ?</strong></p>
  
  <pre><code>public static String PermissionCheck(String FilePath) {
      //File f = new File(FilePath);
      String actions = "read,write";
      try 
      {
        AccessController.checkPermission(new FilePermission(FilePath, actions));
        return ("You have read/write permition to use : " + FilePath);
      }
      catch (SecurityException e) 
      {
        return ("You don't have read/write permition to use : " + FilePath);
      }
  }
  </code></pre>
  
  <p>When I call either with correct path or incorrect path the method it always returns message from cathc.</p>
  
  <p>I know its duplicate question I have already gone through many links but no luck !!</p>
  
  <p><a href="https://stackoverflow.com/questions/1272130/checking-for-write-access-in-a-directory-before-creating-files-inside-it"><strong>Similar Question</strong></a></p>
  
  <p><a href="https://stackoverflow.com/questions/6231779/how-to-check-write-permissions-of-a-directory-in-java"><strong>Similar Question 1</strong></a></p>
  
  <p><strong>Example :</strong> </p>
  
  <pre><code>PreChecks.PermissionCheck("C:/TEST/G2");
  PreChecks.PermissionCheck("C:/Program Files/SAP");
  </code></pre>
  
  <p>Both calls return the message from catch block where I have all permission on "C:/TEST/G2" and no write permission on "C:/Program Files/SAP".</p>
  
  <p><strong>I have also tried canWrite but it says I have write permissions to "C:/Program Files/SAP" but I know I don't have those.</strong></p>