Here you can find the source of recursivelyDelete(File dir)
private static void recursivelyDelete(File dir) throws IOException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.File; import java.io.IOException; public class Main { private static void recursivelyDelete(File dir) throws IOException { if (!dir.getPath().equals(dir.getCanonicalPath())) { // Directory symlink reaching outside of temporary space. return; }/*from w ww .ja va 2 s .com*/ File[] contents = dir.listFiles(); if (contents != null) { for (File d : contents) { if (d.isDirectory()) { recursivelyDelete(d); } else { deleteNowOrOnExit(d); } } } deleteNowOrOnExit(dir); } private static void deleteNowOrOnExit(File dir) { if (!dir.delete()) { dir.deleteOnExit(); } } }