Here you can find the source of deleteAllFilesRecursively(String directoryName)
public static void deleteAllFilesRecursively(String directoryName) throws IOException
//package com.java2s; /*/*w w w .ja v a 2s .c o m*/ * Copyright 2004 by EkoLiving Pty Ltd. All Rights Reserved. * * This software is the proprietary information of EkoLiving Pty Ltd. * Use is subject to license terms. */ import java.io.File; import java.io.IOException; public class Main { public static void deleteAllFilesRecursively(String directoryName) throws IOException { File dir = new File(directoryName); if (dir.exists()) { deleteAllFilesRecursively(dir); dir.delete(); } } public static void deleteAllFilesRecursively(File directory) throws IOException { File[] files = directory.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.exists()) { if (file.isDirectory()) { deleteAllFilesRecursively(file); } if (file.delete() == false) { throw new IOException("Unable to delete " + file.getCanonicalPath()); } } } } }