Here you can find the source of delete(File file)
Parameter | Description |
---|---|
file | The file to be deleted. |
Parameter | Description |
---|---|
IOException | If an I/O error occurs |
public static void delete(File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.nio.file.Files; public class Main { /**//from www . ja v a 2 s . co m * Deletes a file recursively. If <code>file</code> is a non empty directory * the directorys content will be deleted recursively. * * @param file The file to be deleted. * @throws IOException If an I/O error occurs */ public static void delete(File file) throws IOException { if (file.isDirectory()) { File[] children = file.listFiles(); if (children == null) { String msg = "Could not access content of " + file.getAbsolutePath(); throw new IOException(msg); } for (File f : children) delete(f); } Files.delete(file.toPath()); } }