java递归删除目录下所有文件包括目录
import
java.io.File;
public class DelFile {
public static void delAllFile(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
String dirPath = null ;
if (fileList != null ) {
for ( int i = 0 ; i < fileList.length; i ++ ) {
if (fileList[i].isFile()) {
fileList[i].delete();
}
if (fileList[i].isDirectory()){
dirPath = fileList[i].getPath();
delAllFile(dirPath);
}
}
file.delete();
}
}
public static void main(String args[]) {
delAllFile( " C:/analyseFLV " );
}
}
public class DelFile {
public static void delAllFile(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
String dirPath = null ;
if (fileList != null ) {
for ( int i = 0 ; i < fileList.length; i ++ ) {
if (fileList[i].isFile()) {
fileList[i].delete();
}
if (fileList[i].isDirectory()){
dirPath = fileList[i].getPath();
delAllFile(dirPath);
}
}
file.delete();
}
}
public static void main(String args[]) {
delAllFile( " C:/analyseFLV " );
}
}