Java Utililty Methods Directory Delete nio

List of utility methods to do Directory Delete nio

Description

The list of methods to do Directory Delete nio are organized into topic(s).

Method

voiddeleteDir(File dir)
delete Dir
Files.walkFileTree(dir.toPath(), nukeVisitor);
voiddeleteDir(File file)
delete Dir
File[] files = file.listFiles();
if (files != null) {
    for (File temp : files) {
        deleteDir(temp);
try {
    Files.deleteIfExists(file.toPath());
...
voiddeleteDir(final File targetDir)
Elimina un directorio con todo su contenido.
try {
    Files.walkFileTree(targetDir.toPath(), new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
                throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        @Override
        public FileVisitResult postVisitDirectory(final Path dir, final IOException e) throws IOException {
            if (e != null) {
                throw e;
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
    });
} catch (final Exception e) {
    LOGGER.warning("No se pudo borrar el directorio '" + targetDir.getAbsolutePath() + "': " + e); 
voiddeleteDir(String dirName)
delete Dir
deleteDir(new File(dirName));
voiddeleteDir(String path)
delete Dir
if (new File(path).exists())
    Files.walkFileTree(Paths.get(path), new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        @Override
...
voiddeleteDirectory(File dir)
Deletes a directory recursively.
Files.walk(dir.toPath()).map(Path::toFile).sorted(Comparator.reverseOrder()).forEach(File::delete);
voiddeleteDirectory(File dir)
delete Directory
if (dir.exists() && dir.isDirectory()) {
    for (File child : dir.listFiles()) {
        if (child.isDirectory()) {
            deleteDirectory(child);
        } else {
            Files.delete(child.toPath());
    Files.delete(dir.toPath());
booleandeleteDirectory(File directory)
Delete the given directory along with all files and sub directories.
try {
    Files.walk(directory.toPath(), FileVisitOption.FOLLOW_LINKS).sorted(Comparator.reverseOrder())
            .map(Path::toFile).forEach(File::delete);
} catch (IOException e) {
    return false;
return true;
booleandeleteDirectory(File directory)
delete Directory
if (!directory.exists())
    return true;
try {
    Files.delete(directory.toPath());
catch (DirectoryNotEmptyException e) {
    if (directory.listFiles() == null)
        return false;
...
booleandeleteDirectory(File directory)
delete Directory
checkNotNull(directory);
checkArgument(directory.isDirectory(), "File is not directory.");
try {
    Files.walkFileTree(directory.toPath(), new SimpleFileVisitor<Path>() {
        @Nonnull
        @Override
        public FileVisitResult visitFile(@Nonnull Path file, @Nonnull BasicFileAttributes attrs)
                throws IOException {
...