Page 1 of 1

About Question enthuware.ocpjp.ii.v11.2.3336 :

Posted: Sat Oct 09, 2021 4:58 am
by floryan
It will print true if p refers to an empty directory.
What if p cannot be accessed/deleted due to missing permissions?

Re: About Question enthuware.ocpjp.ii.v11.2.3336 :

Posted: Sun Oct 10, 2021 1:10 am
by admin
Already mentioned in the comments under option 4: "It will not throw any exception in that case. It will just return false."

Re: About Question enthuware.ocpjp.ii.v11.2.3336 :

Posted: Wed Oct 13, 2021 12:00 pm
by floryan
Sorry, my bad. Thanks for the response!

Re: About Question enthuware.ocpjp.ii.v11.2.3336 :

Posted: Sun Sep 25, 2022 9:12 am
by sohamdatey22
what, if p is empty, but we don't have file permission. are we supposed to consider that we have permissions, while choosing for
"It will print true if p refers to an empty directory."
we can never be sure, even if the directory is empty. is my understanding.

Re: About Question enthuware.ocpjp.ii.v11.2.3336 :

Posted: Sun Sep 25, 2022 9:20 am
by admin
Yes, you can assume that permission is there. If the question is about permission, the question will tell you about it.

Re: About Question enthuware.ocpjp.ii.v11.2.3336 :

Posted: Tue Jan 16, 2024 9:42 am
by hsnclk
I tested option 1-2-3. It works as you mentioned but when I lock the file on Mac and then try to delete I get exception like this.

Code: Select all

java.nio.file.FileSystemException: /Users/hasancelik/IdeaProjects/gradle/deleted/text.txt: Operation not permitted
	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:100)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
	at java.base/sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:249)
	at java.base/sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:110)
	at java.base/java.nio.file.Files.deleteIfExists(Files.java:1181)
	at oracle_exam7.question21.Test.main(Test.java:17)
But in the option 4, you mention that we would get just "false". Did I misunderstand something?

Re: About Question enthuware.ocpjp.ii.v11.2.3336 :

Posted: Wed Jan 17, 2024 6:52 am
by admin
You are right. As the JavaDoc for this method says, it returns false if the file could not be deleted because it did not exist.
In other cases, it should throw an IOException or SecurityException.
Fixed.
thank you for your feedback!

Re: About Question enthuware.ocpjp.ii.v11.2.3336 :

Posted: Wed Jan 17, 2024 9:09 am
by hsnclk
You're welcome!!!