I want to delete all the files in a folder and its contents. If the file I just use file.delete (); deleted, but the folder does not know how to delete ah. I put all the contents inside the folder deleted, but that can not delete the folder itself, SD card which there has been an empty folder. Experts for advice how to solve this problem.
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
02. Public static void delete (File file) {
03. If (file.isFile ()) {
. 04 file.delete ();
. 05 return;
06.}
07.
08. If (file.isDirectory ()) {
. 09 File [] childFiles = file.listFiles ();
10 if. (ChildFiles == null | | childFiles.length == 0) {
. 11 file.delete ();
. 12 return;
13.}
14.
. 15 for (int i = 0; i16 delete (childFiles [i]);.
17.}
. 18 file.delete ();
19.}
20.}
Reply:
I do not understand why you can delete this approach? You also used. Delete () method to delete ah? I just started to try this method does not delete the folder ah? Is it because this method can only delete empty folders?
Reply:
Yes, you can only delete empty folders ~
Reply:
Files and folders can be deleted
Reply:
I just tried it turned really like ah, blame me delete the stuff inside is no longer about trying to delete the folder. Thank you very much for helping two.
Reply:
Using a recursive method to delete a folder remember Results posted ah!
Reply:
delete (childFiles [i]);
Have
Reply:
delete (childFiles [i]);
There is this way?
Reply:
delete (childFiles [i]);. should be childFiles [i] delete
Reply:
delete (childFiles [i]); are recursive call
No comments:
Post a Comment