When java.io.File#delete fails, this boolean method simply returns false with no indication of the cause. On
the other hand, when java.nio.Files#delete fails, this void method returns one of a series of exception types to better
indicate the cause of the failure. And since more information is generally better in a debugging situation, java.nio.Files#delete is the
preferred option.
public void cleanUp(Path path) {
File file = new File(path);
if (!file.delete()) { // Noncompliant
//...
}
}
public void cleanUp(Path path) throws NoSuchFileException, DirectoryNotEmptyException, IOException{
Files.delete(path);
}