title: How to create directories using java in directories that require sudo rights?
body: <p>I know how to create directories inside any directory using Java. But I am unable to find a solution to add directories inside a directory which requires <code>sudo</code> permission to create a directory inside it.</p>
  
  <p>For eg, I want to create new directories named <code>abc/abc</code> inside <code>/var/log/</code>.</p>
  
  <p>I am uisng following code :</p>
  
  <pre><code>public class CreateDirectories{
      public static void main(String args[]){
      File file = new File("/var/log/java-jdbc/java-jdbc");
          if(!file.exists()){
              if (file.mkdirs()) {
                  System.out.println("Directory is created!");
              } 
              else{
                  System.out.println("Failed to create directory!");
              }
          }
      }
  }
  </code></pre>
  
  <p>This code always runs giving output: <code>Failed to create directory!</code></p>