nerdexam
Oracle

1Z0-805 · Question #26

Given the code fragment: Path path1 = Paths.get("D:\\sales\\.\\quarterly\\..\\report"); path1 = path1.normalize(); Path path2 = path1.relativize(Paths.get("d:\\empdetails.dat")); path2 =…

The correct answer is A. D: \sales\report. Path1 is the normalized result of D:\\sales\\.\\quarterly\\..\\report namely D: \sales\report. The normalize method removes any redundant elements, which includes any "." or "directory/.." Oracle 1Z0-805 Exam With the relativize line path2 is set to../../empdetails.dat In this…

Java I/O Fundamentals

Question

Given the code fragment:

Path path1 = Paths.get("D:\sales\.\quarterly\..\report"); path1 = path1.normalize(); Path path2 = path1.relativize(Paths.get("d:\empdetails.dat")); path2 = path2.resolve(path1); System.out.println(path1); System.out.println(path2); } What is the result?

Options

  • AD: \sales\report
  • B\sales\report
  • CD: \sales\quarterly\ . . . \report
  • D\sales\report
  • ED: \sales\quarterly\ . . .\report
  • F\sales\report\empdetails.dat
  • GD: \sales\report
  • H\sales\report\empdetails.dat

How the community answered

(36 responses)
  • A
    78% (28)
  • B
    11% (4)
  • E
    6% (2)
  • F
    3% (1)
  • G
    3% (1)

Explanation

Path1 is the normalized result of D:\sales\.\quarterly\..\report namely D: \sales\report. The normalize method removes any redundant elements, which includes any "." or "directory/.." Oracle 1Z0-805 Exam With the relativize line path2 is set to../../empdetails.dat In this scenario the following applies to the resolve statement: Passing an absolute path to the resolve method returns the passed-in path.So Path2 will be set to Path1 in the statementpath2 = path2.resolve(path1); A common requirement when you are writing file I/O code is the capability to construct a path from one location in the file system to another location. You can meet this using the relativizemethod. This method constructs a path originating from the original path and ending at the location specified by the passed-in path. The new path is relative to the original path. You can combine paths by using the resolve method. You pass in a partial path , which is a path that does not include a root element, and that partial path is appended to the original path.

Topics

#Path normalization#relativize#resolve#NIO.2

Community Discussion

No community discussion yet for this question.

Full 1Z0-805 Practice