The following method is designed to delete a directory tree recursively.
Which of the following properties reflect the method definition? (Choose all that apply.)
1: public static void deleteTree(File file) { 2: if(!file.isFile()) 3: for(File entry: file.listFiles()) 4: deleteTree(entry); 5: else file.delete(); 6: }
C, F.
The code compiles, so D and E are incorrect.
There is a bug in the method in that file.
delete()
should be executed at the end of the method for both files and directories alike.
As written, the method will delete all files within a directory but none of the directories themselves.
Therefore, A and B are incorrect and C is correct.
F is correct, because most methods in the File class that interact with the file system are capable of throwing an exception at runtime, such as when the directory does not exist.