Recursively delete all files in the directory and all files in the subdirectory

Source: Internet
Author: User

Package com. test;

Import java. Io. file;

Public class filetest3 {

Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Filetest3.dodeleteemptydir ("E: \ new_dir1 ");
String newdir2 = "E: \ hello ";
Boolean success = deleteddir (new file (newdir2 ));
If (SUCCESS ){
System. Out. println ("successfully deleted empty directory:" + newdir2 );
} Else {
System. Out. println ("failed to deleted empty directory:" + newdir2 );
}
}
// Delete the empty folder and empty directory
Private Static void dodeleteemptydir (string DIR ){
Boolean success = new file (DIR). Delete ();
If (SUCCESS ){
System. Out. println ("successfully deleted empty directory:" + DIR );
} Else {
System. Out. println ("failed to deleted empty directory:" + DIR );
}
}

// Recursively delete all files in the directory and all files in the subdirectory
Private Static Boolean deleteddir (File DIR ){
If (dir. isdirectory ()){
String [] children = dir. List ();
For (INT I = 0; I <children. length; I ++ ){
Boolean success = deleteddir (new file (Dir, children [I]);
If (! Success ){
Return false;
}
}
}
Return dir. Delete ();
}

}

Recursively delete all files in the directory and all files in the subdirectory

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.