Consider the following program:
import java.nio.file.*; public class Main { public static void main(String []args) { Path javaPath = Paths.get("D:\\OCPJP7\\programs\\NIO2\\src\\Main.java").normalize(); Path classPath =Paths.get("D:\\OCPJP7\\programs\\NIO2\\src\\Main.class").normalize(); Path result = javaPath.relativize(classPath); if(result == null) { System.out.println("relativize failed"); } else if(result.equals(Paths.get(""))) { System.out.println("relative paths are same, so relativize returned empty path"); } else { System.out.println(result); }// w w w .j ava 2s .c o m } }
Which of the following options correctly shows the output of this program?
C)
The relativize()
method constructs a relative path between this path and a given path.
In this case, the paths for both the files are the same and they differ only in the file names (Main.java and Main.class).
The relative comparison of paths is performed from the given path to the passed path to the relativize method, so it prints ..\Main.class.
The normalize()
method removes any redundant name elements in a path.
In this program, there are no redundant name elements, so it has no impact on the output of this program.