Here you can find the source of delete(File file)
public static void delete(File file) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class Main { public static void delete(File file) throws IOException { if (file.isDirectory()) { deleteDirectory(file);//from www .j av a 2s. c om return; } Files.delete(Paths.get(file.getPath())); } public static void deleteDirectory(File directory) throws IOException { cleanDirectory(directory); Files.delete(Paths.get(directory.getAbsolutePath())); } public static void cleanDirectory(File directory) throws IOException { if (!directory.isDirectory()) { throw new IllegalArgumentException(directory + " is not a directory"); } File[] files = directory.listFiles(); if (files == null) { throw new IOException("Failed to list contents of " + directory); } for (File file : files) { delete(file); } } }