private static void DeleteFile (file file) {if (file.exists ())//Determines whether the file exists return;if (File.isfile ()) {//Determines whether the file is File.delete ();//delete file} else if (File.isdirectory ()) {//Otherwise if it is a directory file[] files = file.listfiles ();//Declare all files under the directory files[];for (int i = 0; i < files.length; i++) {//Traverse directory All Files DeleteFile (files[i]);//Use this method for each file to iterate}file.delete ();//delete folder}}public static void DeleteDirectory ( File file) {if (!file.exists ()) return;if (File.isfile ()) {file.delete (); return;} else {//First get current path string[] Childfilepaths = File.list (); for (String childfilepath:childfilepaths) {File Childfile = new file (File.getabsolutepath ( ) + "/" + Childfilepath);d eletedirectory (childfile);} File.delete ();}}
Java Delete folder