Here you can find the source of delete(Path path)
public static void delete(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 { public static void delete(Path path) throws IOException { if (!Files.exists(path)) { return; }//from www .j a v a 2 s . c o m if (Files.isRegularFile(path)) { Files.delete(path); } else { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { Files.delete(path); return super.visitFile(path, basicFileAttributes); } @Override public FileVisitResult postVisitDirectory(Path path, IOException e) throws IOException { Files.delete(path); return super.postVisitDirectory(path, e); } }); } } }