Compare two file paths - Java File Path IO

Java examples for File Path IO:Path

Description

Compare two file paths

Demo Code


import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
   //from   ww w. java  2s . c  o  m
    //create first file object
    File file1 = new File("C://Folder//demo1.txt");
   
    //create second file object
    File file2 =  new File("C://Folder//demo1.txt");
   
   
     if(file1.compareTo(file2) == 0)
     {
       System.out.println("Both paths are same!");
     }
     else
     {
       System.out.println("Paths are not same!");
     }
  }
}

Result


Related Tutorials