I am trying to create a directory in Java. If it exists, I want to delete this directory and its contents and create a new one. I am trying to do the following, but the directory is not deleted. New files are added to the directory.
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"); }
I create this directory at runtime in the directory of a running project. After each launch, the old content must be deleted, and the new content must be present in this directory.
source share