java files

import java.io.File;

Table of Contents

Program

public class FileBooleanEquals {
 
    public static void main(String[] args) {
 
        File file1 = new File("c:\\program\\test.txt");
        File file2 = file1;
 
        File file3 = new File("c:\\program\\hello.txt");
 
        System.out.println("Is file1 equal to file2 ? " + file1.equals(file2));
 
        System.out.println("Is file1 equal to file3 ? " + file1.equals(file3));
 
    }
}

Output

Is file1 equal to file2 ? true
Is file1 equal to file3 ? false 

Description

public boolean equals​(Object obj)

Tests this abstract pathname for equality with the given object. Returns true if and only if the argument is not null and is an abstract pathname that denotes the same file or directory as this abstract pathname. Whether or not two abstract pathnames are equal depends upon the underlying system. On UNIX systems, the alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.

Overrides:

equals in class Object

Parameters:

obj – The object to be compared with this abstract pathname

Returns:

true if and only if the objects are the same; false otherwise