What if p cannot be accessed/deleted due to missing permissions?It will print true if p refers to an empty directory.
About Question enthuware.ocpjp.ii.v11.2.3336 :
Moderator: admin
-
- Posts: 17
- Joined: Sun Sep 23, 2018 4:10 am
- Contact:
About Question enthuware.ocpjp.ii.v11.2.3336 :
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3336 :
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.
-
- Posts: 17
- Joined: Sun Sep 23, 2018 4:10 am
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3336 :
Sorry, my bad. Thanks for the response!
-
- Posts: 28
- Joined: Sun Sep 11, 2022 3:55 am
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3336 :
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.
"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.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3336 :
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.
-
- Posts: 16
- Joined: Sat Dec 16, 2023 7:22 am
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3336 :
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.
But in the option 4, you mention that we would get just "false". Did I misunderstand something?
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)
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3336 :
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!
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.
-
- Posts: 16
- Joined: Sat Dec 16, 2023 7:22 am
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3336 :
You're welcome!!!
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 37 guests