Here you can find the source of deleteRecursive(Path path)
Parameter | Description |
---|---|
path | path to delete |
Parameter | Description |
---|---|
IOException | if the path can not be visited |
public static void deleteRecursive(Path path) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; public class Main { /**// w w w . j ava 2 s . co m * Recursively delete the given path * @param path path to delete * @throws IOException if the path can not be visited */ public static void deleteRecursive(Path path) throws IOException { Files.walkFileTree(path, 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; } } }); } }