Java OCA OCP Practice Question 2890

Question

What is correct about the following code snippet? (Choose all that apply.)

Files.move(Paths.get("sql.txt"), Paths.get("/data"), 
  StandardCopyOption.ATOMIC_MOVE, 
  LinkOption.NOFOLLOW_LINKS); 
  • A. If /data exists, it will be overwritten at runtime.
  • B. If sql.txt is a symbolic link, the file it points to will be moved at runtime.
  • C. If another process is monitoring the file system, it will not see an incomplete file at runtime.
  • D. The code will always throw an exception, since no filename is specified in the target folder path.
  • E. The metadata of the sql.txt will be moved along with the file.


C, E.

Note

The REPLACE_EXISTING flag was not provided, so if the target exists, it will throw an exception at runtime and A is incorrect.

Next, the NOFOLLOW_LINKS option means that if the source is a symbolic link, the link itself and not the target will be copied at runtime, so B is also incorrect.

The option ATOMIC_MOVE means that any process monitoring the file system will not see an incomplete file during the move, so C is correct.

D is incorrect, since you could rename a file not to have an extension.

Note that in this example, if sql.

txt is a file, then the resulting /data would be a file, not a directory.

Likewise, if the source is a directory, the result would also be a directory.

E is correct, because moving always preserves the metadata even if the COPY_ATTRIBUTES flag is not set.




PreviousNext

Related