Compare Two File Paths In Java
Chapter:
File
Last Updated:
17-04-2016 16:47:37 UTC
Program:
/* ............... START ............... */
import java.io.*;
public class JavaCompareTwoFilePath {
public static void main(String[] args) {
File file1 = new File("C://File//File1.txt");
File file2 = new File("C://File//File2.txt");
if (file1.compareTo(file2) == 0) {
System.out.println("Both paths are same!");
} else {
System.out.println("Paths are not same!");
}
}
}
/* ............... END ............... */
Notes:
-
Two file paths are comparing using compareTo method of Java.
- compareTo method returns 0 of both paths are same, integer less than 0 if file path is less than that of argument, and positive integer if the file path is grater than that of argument.
Tags
Compare Two File Paths, Java