Java Recursive delete system files

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.