adsense


Monday, 26 October 2015

JAVA EXAMPLES FILE PATH COMPARISON PAGE 87

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES FILE PATH COMPARISON


Java Examples - File path Comparison



Problem Description:
How to compare paths of two files ?
Solution:
This example shows how to compare paths of two files in a same directory by the use of filename.compareTo (another filename) method of File class.
import java.io.File;

public class Main {
   public static void main(String[] args) {
      File file1 = new File("C:/File/demo1.txt");
      File file2 = new File("C:/java/demo1.txt");
      if(file1.compareTo(file2) == 0) {
         System.out.println("Both paths are same!");
      } else {
         System.out.println("Paths are not same!");
      }
   }
}
Result:
The above code sample will produce the following result.
Paths are not same!


No comments: