Here you can find the source of deleteDirectory(Path directory)
Parameter | Description |
---|---|
directory | a parameter |
public static boolean deleteDirectory(Path directory)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; public class Main { /**/*from w ww.java2 s .com*/ * Deletes a directory recursively * * @param directory * @return true if deletion succeeds, false otherwise */ public static boolean deleteDirectory(Path directory) { if (directory != null) { try { Files.walkFileTree(directory, 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 exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); } catch (IOException ignored) { return false; } } return true; } }