Java tutorial
//package com.java2s; import java.io.File; public class Main { public static void defileFile(File file) { if (file.isFile()) { file.delete(); return; } if (file.isDirectory()) { File[] childFiles = file.listFiles(); if (childFiles == null || childFiles.length == 0) { file.delete(); return; } for (File f : childFiles) { defileFile(f); } file.delete(); } } public static boolean isDirectory(String dir, String fileName) { return (new File(joinPath(dir, fileName)).isDirectory()); } public static String joinPath(String... args) { StringBuilder stringBuilder = new StringBuilder(); for (String arg : args) { stringBuilder.append(File.separator).append(arg.replaceAll("^/+", "")); } return stringBuilder.toString(); } }