Check if two paths are the same file/folder. - Java File Path IO

Java examples for File Path IO:Path


Check if two paths are the same file/folder.

Demo Code

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) {
    Path path01 = Paths.get("/folder1/folder2/folder3/test.txt");
    Path path02 = Paths.get("C:/folder1/folder2/folder3/test.txt");

    // compare using Files.isSameFile
    try {/*w  w  w.  j  a  v a2s  .  co  m*/
      boolean check = Files.isSameFile(path01, path02);
      if (check) {
        System.out.println("The paths locate the same file!");
      } else {
        System.out.println("The paths does not locate the same file!");
    } catch (IOException e) {



Related Tutorials