Here you can find the source of clearDirectory(File dir, boolean doTree)
Parameter | Description |
---|---|
dir | A directory, which exists |
doTree | If true, then we will clear all subdirectories |
public static void clearDirectory(File dir, boolean doTree)
//package com.java2s; import java.io.File; public class Main { /**/*w ww. j a v a 2s . co m*/ Delete every file within a directory. If there are any problems, the routine silently returns. @param dir A directory, which exists @param doTree If true, then we will clear all subdirectories */ public static void clearDirectory(File dir, boolean doTree) { // get a list of the files String[] fileList = dir.list(); if (fileList == null) { // this isn't a directory return; } for (int ii = 0; ii < fileList.length; ii++) { File subFile = new File(dir, fileList[ii]); if (subFile.isDirectory()) { if (doTree) { clearDirectory(subFile, true); subFile.delete(); } } else { subFile.delete(); } } return; } }