How to compare two file paths using compareTo() method in Java

2 Answers

0 votes
package javaapplication1;

import java.io.File;
import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        File file1 = new File("d://data.txt");
        File file2 = new File("d://three_letters_combination.txt");

        if (file1.compareTo(file2) == 0) {
            System.out.println("Paths are same");
        } else {
            System.out.println("Paths are not same");
        }
    }
}
 
/*
       
run:
 
Paths are not same
   
*/

 



answered Nov 14, 2016 by avibootz
0 votes
package javaapplication1;

import java.io.File;
import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        File file1 = new File("d:\\directx\\3d\\3d\\main.cpp");
        File file2 = new File("d:\\directx\\3d\\3d\\main.cpp");

        if (file1.compareTo(file2) == 0) {
            System.out.println("Paths are same");
        } else {
            System.out.println("Paths are not same");
        }
    }
}
 
/*
       
run:
 
Paths are same
   
*/

 



answered Nov 14, 2016 by avibootz

Related questions

1 answer 182 views
1 answer 176 views
1 answer 175 views
1 answer 185 views
1 answer 182 views
1 answer 192 views
...