Here you can find the source of delete(Path root)
Parameter | Description |
---|---|
root | path to the file. |
Parameter | Description |
---|---|
IOException | thrown on filesystem error. |
public static void delete(Path root) throws IOException
//package com.java2s; // License as published by the Free Software Foundation; either import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; public class Main { /**/*ww w . j av a 2 s .com*/ * Deletes the file, if it is a directory, deletes its content recursively. * * @param root * path to the file. * @throws IOException * thrown on filesystem error. */ public static void delete(Path root) throws IOException { if (Files.isDirectory(root)) { final DirectoryStream<Path> subPaths = Files.newDirectoryStream(root); for (Path path : subPaths) { delete(path); } subPaths.close(); Files.delete(root); } else { Files.delete(root); } } }