Java IO & NIO Java Java API
java.nio.file.Files
public static boolean isSameFile(Path path, Path path2) throws IOException
Tests whether two paths point to the same file.
path
path2
true
package com.logicbig.example.files;import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;import java.nio.file.Paths;public class IsSameFileExample { public static void main(String... args) throws IOException { Path path = Files.createTempFile("test-file", ".txt"); Path otherPath = Paths.get(path.toString()); boolean sameFile = Files.isSameFile(path, otherPath); System.out.println(sameFile); Path anotherPath = Files.createTempFile("test-file", ".txt"); sameFile = Files.isSameFile(path, anotherPath); System.out.println(sameFile); }}
truefalse