Here you can find the source of createOverwriteDirectory(Path path)
Parameter | Description |
---|---|
path | path to the directory. |
Parameter | Description |
---|---|
IOException | thrown on filesystem error. |
public static void createOverwriteDirectory(Path path) 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 a v a2s . c o m*/ * Creates new directory or overwrites existing one. * * @param path * path to the directory. * @throws IOException * thrown on filesystem error. */ public static void createOverwriteDirectory(Path path) throws IOException { if (Files.exists(path)) { delete(path); } Files.createDirectory(path); } /** * 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); } } }