"Assuming that the file module-info.java and the folder out\foo.bar exists". I think you can read this as the file exists in path p1 (instead of p2) what makes the answer different.
Other thing. In the answer is mentioned that "it copies a file", but I guess this should be "it moves a file". In class Files is metioned:
public static Path move(Path source, Path target, CopyOption... options) throws IOException
Move or rename a file to a target file.
By default, this method attempts to move the file to the target file, failing if the target file exists except if the source and target are the same file, in which case this method has no effect.
About Question enthuware.ocpjp.v11.2.3335 :
Moderator: admin
-
- Posts: 6
- Joined: Sun Feb 07, 2021 9:49 am
- Contact:
-
- Site Admin
- Posts: 10165
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3335 :
You are right. Updated.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
-
- Posts: 24
- Joined: Wed Sep 28, 2022 9:41 am
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3335 :
Hello, one doubt..
In the code:
Path p1 = Paths.get("c:\\temp\\src\\foo.bar\\module-info.java");
Path p2 = Paths.get("c:\\temp\\out\\foo.bar"); //foo.bar is a folder
Files.move(p1, p2, REPLACE_EXISTING );
Question 01: The file "module-info.java" would be copied "overwriting" on top "foo.bar", even IF the foo.bar folder was "not-empty"?
Question 02: The file "module-info.java" would be copied "overwriting" on top "foo.bar", even IF the foo.bar folder was "empty"?
Thanks
In the code:
Path p1 = Paths.get("c:\\temp\\src\\foo.bar\\module-info.java");
Path p2 = Paths.get("c:\\temp\\out\\foo.bar"); //foo.bar is a folder
Files.move(p1, p2, REPLACE_EXISTING );
Question 01: The file "module-info.java" would be copied "overwriting" on top "foo.bar", even IF the foo.bar folder was "not-empty"?
Question 02: The file "module-info.java" would be copied "overwriting" on top "foo.bar", even IF the foo.bar folder was "empty"?
Thanks
Last edited by edufin166@yahoo.com on Fri Jun 09, 2023 1:54 pm, edited 1 time in total.
-
- Site Admin
- Posts: 10165
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3335 :
If you try to copy module-info.jar onto foo.bar, then the JavaDoc API doesn't define what will happen.
On my windows machine it throws FileAlreadyExistsException.
You may read more about it here: https://docs.oracle.com/en/java/javase/ ... CopyOption...)
On my windows machine it throws FileAlreadyExistsException.
You may read more about it here: https://docs.oracle.com/en/java/javase/ ... CopyOption...)
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 4 guests