Here you can find the source of deleteRecursive(File file)
Parameter | Description |
---|---|
file | a parameter |
public static void deleteRecursive(File file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { /**//from ww w. j a v a2 s . c o m * Recursively deletes a file/folder and all its subcontent. * In other words, "rm -rf" * @param file */ public static void deleteRecursive(File file) { List<File> exploreQueue = new ArrayList<File>(); List<File> exploreQueue2 = new ArrayList<File>(); List<File> deleteQueue = new ArrayList<File>(); exploreQueue.add(file); while (!exploreQueue.isEmpty()) { deleteQueue.addAll(0, exploreQueue); for (File toExplore : exploreQueue) { if (toExplore.isDirectory()) { for (File child : toExplore.listFiles()) { exploreQueue2.add(0, child); } } } exploreQueue.clear(); exploreQueue.addAll(exploreQueue2); exploreQueue2.clear(); } for (File toDelete : deleteQueue) { toDelete.delete(); } } }