title: Create directory. If exists, delete directory and its content and create new one in Java
body: <p>I am trying to make a directory in Java. If it exists, I want to delete that directory and its content and make a new one. I am trying to do the following, but the directory is not deleted. New files are appended to the directory. </p>
  
  <pre><code>File file = new File("path");
  boolean isDirectoryCreated = file.mkdir();
     if (isDirectoryCreated) {
         System.out.println("successfully made");
          } else {
            file.delete();
            file.mkdir();
            System.out.println("deleted and made");
            }
  </code></pre>
  
  <p>I am creating this directory in runtime in the directory of the running project. After every run, the old contents have to be deleted and new content has to be present in this directory.</p>