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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
floryan
Posts: 17
Joined: Sun Sep 23, 2018 4:10 am
Contact:

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

Post by floryan »

It will print true if p refers to an empty directory.
What if p cannot be accessed/deleted due to missing permissions?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Already mentioned in the comments under option 4: "It will not throw any exception in that case. It will just return false."
If you like our products and services, please help us by posting your review here.

floryan
Posts: 17
Joined: Sun Sep 23, 2018 4:10 am
Contact:

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

Post by floryan »

Sorry, my bad. Thanks for the response!

sohamdatey22
Posts: 28
Joined: Sun Sep 11, 2022 3:55 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, you can assume that permission is there. If the question is about permission, the question will tell you about it.
If you like our products and services, please help us by posting your review here.

hsnclk
Posts: 16
Joined: Sat Dec 16, 2023 7:22 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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!
If you like our products and services, please help us by posting your review here.

hsnclk
Posts: 16
Joined: Sat Dec 16, 2023 7:22 am
Contact:

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

Post by hsnclk »

You're welcome!!!

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 39 guests