A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/file_compare.htm below:

How to compare paths of two files in Java

How to compare paths of two files in Java 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!

java_files.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4