Java Files.isSameFile(Path path, Path path2)

Syntax

Files.isSameFile(Path path, Path path2) has the following syntax.

public static boolean isSameFile(Path path,   Path path2)    throws IOException

Example

In the following code shows how to use Files.isSameFile(Path path, Path path2) method.


/*  w w  w .  j  av  a 2 s .  c  om*/

import java.io.IOException;
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("/tutorial/Java/JavaFX/Topic.txt");
    Path path02 = Paths.get("C:/tutorial/Java/JavaFX/Topic.txt");

    // compare using Files.isSameFile
    try {
      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) {
      System.out.println(e);
    }
  }
}




















Home »
  Java Tutorial »
    java.nio.file »




DirectoryStream.Filter
Files
FileStore
FileSystem
FileVisitor
Path
Paths
WatchService