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());
}
What is the result?
A.
D:\sys\mfg\production.log
8
B.
D:\\sys\\asm\\.\\data\\. . \\mfg\\production.log
6
C.
D: \\sys\\asm\\.\\data\\. . \\mfg\\production.log
8
D.
D: \sys\mfg\production.log
4
E.
D: \\ sys\\asm\\data\\mfg\\production.log
6
Explanation:
The normalize method removes any redundant elements, which includes any “.” or
“directory/..” occurrences.
ThegetNameCount method returns the number of elements in the path.Here there are 8 elements
(in the redundant path).
Reference: The Java Tutorials,Path Operations