Java File Delete nio deleteAll(File f)

Here you can find the source of deleteAll(File f)

Description

delete All

License

Open Source License

Declaration

public static void deleteAll(File f) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

public class Main {
    public static void deleteAll(File f) {

        Path start = FileSystems.getDefault().getPath(f.getAbsolutePath());
        try {/*ww w.ja va2s.  c om*/
            Files.walkFileTree(start, new SimpleFileVisitor<Path>() {

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    Files.delete(file);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
                    if (e == null) {
                        Files.delete(dir);
                        return FileVisitResult.CONTINUE;
                    } else {
                        // directory iteration failed
                        throw e;
                    }
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. delete(File file)
  2. delete(File file)
  3. delete(File file)
  4. delete(File toRecurse)
  5. delete(final File directory, final FileFilter fileFilter)
  6. deleteAll(File file)
  7. deleteEntriesFromZip(File zipFile, List entriesToDelete)
  8. deleteFile(File f)
  9. deleteFile(File f)