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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

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: 10384
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."

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: 10384
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.

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: 10384
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!

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: No registered users and 13 guests