检查两个路径是否指向同一个文件
/*时 代 Java - nowjava.com 提 供*/ import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; public class Main { public static void main(String[] args) { Path path_1 = FileSystems.getDefault().getPath( "C:/folder1/folder2/folder4", "my.txt"); Path path_2 = FileSystems.getDefault().getPath( "/folder1/folder2/folder4", "my.txt"); Path path_3 = FileSystems.getDefault().getPath( "/folder1/folder2/dummy/../folder4", "my.txt"); try { boolean is_same_file_12 = Files.isSameFile(path_1, path_2); boolean is_same_file_13 = Files.isSameFile(path_1, path_3); boolean is_same_file_23 = Files.isSameFile(path_2, path_3); System.out.println("is same file 1&2 ? " + is_same_file_12); System.out.println("is same file 1&3 ? "