Java program deletes system files or folders
- The delete () method of the file object can only delete files or empty folders
- The listfiles () method of the file object can traverse all files and folders under the folder
- The file Object isdirectory () method determines whether the current object is a folder
- The file Object isfile () method determines whether the current object is a document
Using the above methods can be done to delete the system files, as long as the appropriate path to pass
1 Public Static voidmothd (file file) {2 if(File.isdirectory ()) {3 //kill all of your child files and subdirectories4 //get all sub-files and subdirectories5file[] Files =file.listfiles ();6 for(File f:files) {7 if(F.isfile ()) {8 //Delete directly9 System.out.println (F.getname ());Ten F.delete (); One}Else if(F.isdirectory ()) { A //continue to see if files and subdirectories are still available - MOTHD (f); - } the } - - - File.delete (); + } -}
Specific code implementation, in addition to seeking non-recursive deletion, seek the help of the great God, after all, recursion too much memory.
Java Recursive delete system files