title: How to check write permissions of a directory in java? Can we change it?
body: <p>I am using the code below, but it’s not working. The method <code>canWrite()</code> is not working, even if changing the rights for writing for a directory.</p>
  
  <pre><code>File file = new File(fc.getSelectedFile().getAbsolutePath());
  // fc is a FileChooser object
  if(f.canWrite()) 
  {
    // write access
  } 
  else 
  {
    // no write access
  }
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>try 
  {
      AccessController.checkPermission(new FilePermission("/tmp/*", "read,write"));
      System.out.println("Good");
      // Has permission
  }
  catch (SecurityException e) 
  {
  // Does not have permission
  System.out.println("Bad");
  }
  </code></pre>