Book : Oracle Certified Professional Java SE8 Programmer 2 (IZO-809)
I have a question regarding Chapter 8(IO): Question 10 (pg 447).
A. It can delete a directory that contains only files
B. It can delete a directory tree of arbitrary length
C. It can delete a single file. -
D. It compiles but may throw an exception at runtime
The book says that C and D are correct answer but from what the code is doing, it looks like it's able to delete recursively all the files. So to me, looks like the code can delete a directory tree of any arbitrary lenght, it's just that it can't delete the directory itself.
Welcome to CodeRanch! I've added the publisher name to the subject (a number of books have similar sounding names.)
My copy of the book lists C and F as answers to #10. We have an errata that F is debatable. But D was never a correct answer. Can you double check that your book does say D for that question. (And if so, can you post a picture that contains the page # and that answer?
Thanks for the quick reply, and i'm sorry i did not post the question properly the first time. I'm attaching the answer pictures in this thread.
You are correct, that D : The code will not compile because of line 2 was never the answer because the code compiles without any issue. My only question was regarding C : It can delete a single file. While it can delete a single file, the code can also recursively clean the entire directory as well. That's where the answer C (It can delete a single file ) confused me.
So while i think that C is correct, I want to make sure that i'm reading the code snippet correctly when i'm saying that it's able to also recursively delete "ALL" the files in the directory as well. In other words, i fail to see how the code snippet could only delete only a single file in the directory.
I"m pleased your copy of the book matches mine and says "C and F." (There was a recent thread where the reader's copy was different than mine. It turned out the publisher had incorrectly fixed an errata.)
Anyway, back to C. Suppose you call the method with new File("/my/path/a.txt"). It will delete a.txt because the else block will run.
That does make sense. No i see what the question was trying to make me understand.
Appreciate your quick response.
BTW, do you have a list of all the erratas that have been submitted for this book ? i was thinking it would be in the Sybex website (https://testbanks.wiley.com) but i'm not able to find it there.