Comparing Two Paths - Java File Path IO

Java examples for File Path IO:Path

Description

Comparing Two Paths

Demo Code

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("/folder1/folder2/folder3/test.txt");
        Path path02 = Paths.get("C:/folder1/folder2/folder3/test.txt");

        //compare using Path.equals
        if (path01.equals(path02)) {
            System.out.println("The paths are equal!");
        } else {/*from ww  w . ja v  a2 s. c  o m*/
            System.out.println("The paths are not equal!");
        }

    }
}

Result


Related Tutorials