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