Java IO & NIO Java Java API
Class:
java.nio.file.Files
Method:
public static boolean isSameFile(Path path,
Path path2)
throws IOException
Tests whether two paths point to the same file.
- Parameters:
-
path
- one path to the file
-
path2
- the other path
- Returns:
-
true
if, and only if, the two paths locate the same file
Examples
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); } }
Outputtrue false
|
|