Here you can find the source of deleteEmptyDir(File file)
public static void deleteEmptyDir(File file)
//package com.java2s; import java.io.File; import java.util.List; public class Main { public static void deleteEmptyDir(File file) { if (!file.exists() || file.isFile()) { return; }//from w w w .java2s. c o m if (file.isDirectory()) { if (file.list().length == 0) { file.delete(); } else { for (File f : file.listFiles()) { deleteEmptyDir(f); } if (file.list().length == 0) { file.delete(); } } } } public static void deleteEmptyDir(File file, List<File> deleteList) { if (!file.exists() || file.isFile()) { return; } if (file.isDirectory()) { if (file.list().length == 0) { deleteList.add(file); file.delete(); } else { for (File f : file.listFiles()) { deleteEmptyDir(f, deleteList); } if (file.list().length == 0) { deleteList.add(file); file.delete(); } } } } }