Here you can find the source of deleteRecursively(File fileOrDir)
public static void deleteRecursively(File fileOrDir) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { public static void deleteRecursively(File fileOrDir) throws IOException { if (fileOrDir.isFile()) { deleteFile(fileOrDir);/*w w w . ja va 2 s. co m*/ } else if (fileOrDir.isDirectory()) { String[] names = fileOrDir.list(); if (names != null) { for (String name : names) { deleteRecursively(new File(fileOrDir, name)); } } if (!fileOrDir.delete()) { throw new IOException("Could not delete dir: " + fileOrDir); } } else { throw new IOException("Neither file nor dir: " + fileOrDir); } } public static void deleteFile(File file) throws IOException { if (!file.delete()) { throw new IOException("Could not delete file: " + file); } } }