The
instance is as follows:
Package com.xx;
Import Java.io.File;
public class Test {public static void main (string[] args) {String fileroot = "c:/users/xx/desktop/xx/xxx";
Delfolder (Fileroot);
System.out.println ("deleted"); /////Delete folder////param FolderPath folder full absolute path public static void Delfolder (String folderpath) {try {Delall File (FolderPath);
Delete all contents inside//Do not want to delete the best clip hidden below//String FilePath = FolderPath;
FilePath = Filepath.tostring ();
Java.io.File Myfilepath = new Java.io.File (FilePath); Myfilepath.delete ();
Delete Empty folders} catch (Exception e) {e.printstacktrace ();
}///delete all files//param path folder full absolute path public static Boolean delallfile (String path) {Boolean flag = False in the specified folder;
File File = new file (path);
if (!file.exists ()) {return flag;
} if (!file.isdirectory ()) {return flag;
} string[] Templist = File.list ();
File temp = null; for (int i = 0; i < templist.length i++) {if (Path.endswith (file.separator)) {Temp = new File (path + templist[i]);
else {temp = new File (path + file.separator + templist[i]);
} if (Temp.isfile ()) {temp.delete (); } if (Temp.isdirectory ()) {Delallfile (path + "/" + templist[i])//delete file in Folder//Delfolder (path + "/" + Templi
St[i]);/delete empty folder flag = true;
} return flag;
}
}
The above Java Delete all the contents of the folder without deleting the folder itself is a small series to share all the content, I hope to give you a reference, but also hope that we support the cloud-dwelling community.