Here you can find the source of deleteFiles(File[] files)
public static void deleteFiles(File[] files) throws IOException
//package com.java2s; import java.io.File; import java.io.IOException; public class Main { public static void deleteFiles(File[] files) throws IOException { for (File file : files) { if (file.isDirectory()) { deleteFolder(file);/*from w w w . j a v a 2 s. c o m*/ } else { file.delete(); } } } /** * Delete a folder and its contents * @param afolder - a folder */ public static void deleteFolder(File afolder) throws IOException { if (afolder == null) { return; } // Not root directories // This way does not work where afolder = new File("aFolder"); // File parent = afolder.getParentFile(); File parent = new File(afolder.getAbsolutePath()).getParentFile(); if (parent == null) { throw new IOException("Cannot delete root folder"); //$NON-NLS-1$ } if (afolder.exists() && afolder.isDirectory()) { //delete content of directory: File[] files = afolder.listFiles(); int count = files.length; for (int i = 0; i < count; i++) { File f = files[i]; if (f.isFile()) { f.delete(); } else if (f.isDirectory()) { deleteFolder(f); } } afolder.delete(); } } }