file
Delete a file or a directory in Java. Directory must not be empty.
import java.io.IOException;
import java.nio.file.*;
try {
Files.deleteIfExists(Paths.get("filepath"));
}
catch(NoSuchFileException e)
{
// file does not exists
}
catch(DirectoryNotEmptyException e)
{
// attempt to delete a directory that is not empty
}
catch(IOException e)
{
// other issues (such as permissions)
}