nerdexam
Oracle

1Z0-805 · Question #45

Given the code fragment: public class Test { public static void main (String [] args) { Path path1 = Paths.get("D:\\sys\\asm\\.\\data\\..\\..\\mfg\\production.log")…

The correct answer is A. D:\sys\mfg\production.log. The normalize method removes any redundant elements, which includes any "." or "directory/.." ThegetNameCount method returns the number of elements in the path.Here there are 8 elements (in the redundant path).

Java I/O Fundamentals

Question

Given the code fragment:

public class Test { public static void main (String [] args) { Path path1 = Paths.get("D:\sys\asm\.\data\..\..\mfg\production.log"); System.out.println(path1.normalize()); System.out.println(path1.getNameCount()); } } Oracle 1Z0-805 Exam What is the result?

Options

  • AD:\sys\mfg\production.log
  • BD:\sys\asm\.\data\. . \mfg\production.log
  • CD: \sys\asm\.\data\. . \mfg\production.log
  • DD: \sys\mfg\production.log
  • ED: \ sys\asm\data\mfg\production.log

How the community answered

(40 responses)
  • A
    80% (32)
  • B
    3% (1)
  • C
    3% (1)
  • D
    5% (2)
  • E
    10% (4)

Explanation

The normalize method removes any redundant elements, which includes any "." or "directory/.." ThegetNameCount method returns the number of elements in the path.Here there are 8 elements (in the redundant path).

Topics

#Path normalize#getNameCount#path traversal#NIO.2

Community Discussion

No community discussion yet for this question.

Full 1Z0-805 Practice