Here you can find the source of cleanDirectory(final File directory)
private static void cleanDirectory(final File directory) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/*from www .j a va 2 s .co m*/ * Clean a directory without deleting it. */ private static void cleanDirectory(final File directory) throws IOException { if (!directory.exists()) { return; } if (!directory.isDirectory()) { return; } IOException exception = null; final File[] files = directory.listFiles(); if (files != null) { for (final File file : files) { try { cleanDirectory(file); if (!file.delete()) { throw new IOException("Cannot delete " + file.getAbsolutePath()); } } catch (final IOException ioe) { exception = ioe; } } } if (null != exception) { throw exception; } } }