ImportJava.io.File;/** * @authorPirate Captain * February 14, 2017 11:24:26*/ Public classDeletefiles { Public Static voiddeletefiles (file file) {if(File.isdirectory ()) {//if it is a directory, look for all the files or directories under this directory first//and then delete it according to the situationfile[] Files =File.listfiles (); if(Files.length = = 0 ){ //if it is an empty directory, delete it directlyFile.delete (); } Else { //if it is not an empty directory, the recursive for(File f:files) {deletefiles (f); //after the recursion is deleted, delete the directoryF.delete (); } } } Else { //if it is a file, delete it directlyFile.delete (); } } Public Static voidMain (string[] args) {
System.out.println ("Start Execution"); File File=NewFile ("D:\\Program Files"); Deletefiles (file);
SYSTEM.OUT.PRINTLN ("Done! "); } }
Source file name length is greater than system supported length, cannot be deleted, Java Main method execution method delete