I want to create and delete a directory using Java, but it isn\'t working.
File index = new File(\"/home/Work/Indexer1\");
if (!index.exists()) {
index.m
2020 here :)
With Apache commons io FileUtils, contrary to the "pure" Java variants a folder does not need to be empty to be deleted. To give you a better overview I list the variants here, the following 3 may throw exceptions for various reasons:
The following variant never throws exceptions (even if the file is null !)
One more thing to know is dealing with symbolic links, it will delete the symbolic link and not the target folder... be careful.
Also keep in mind that deleting a large file or folder can be a blocking operation for a good while ... so if you do not mind having it run async do it (in a background thread via executor for example).