Exam Objectives

Use Path interface to operate on file and directory paths.
Use Files class to check, read, delete, copy, move, manage metadata of a file or directory.


1. The correct answer is C.
Path.resolve() doesn't remove redundancy in paths (that's done with Path.normalize() or Path.toRealPath()), it just combines two paths.

2. The correct answer is B.
path.getRoot() returns c:\
path.getName(0) returns Users
path.getName(1) returns mark
path.subpath(0,0) throws an exception

getName() returns the element parts of a path. The first element is at index zero (the root doesn't count as an element).

3. The correct answer is C.
CopyOption is an interface implemented by the enumerations StandardCopyOptions (with the values ATOMIC_MOVE (not supported), REPLACE_EXISTING, COPY_ATTRIBUTES) and LinkOption (with the value NOFOLLOW_LINKS).

4. The correct answer is D.
. means the current directory and .. means the parent directory. The method toRealPath() turns the redundant path into C:\temp\file.txt. path.subpath(1,2) give us the element at index 1, file.txt.

5. The correct answer is D.
A file creation time attribute can only be set with BasicFileAttributeView. The right way to do it is with a FileTime instance as shown in Option D.