Java File Class equals() Method with Examples Last Updated : 02 Feb, 2022 Comments Improve Suggest changes Like Article Like Report The equals() method of Java File Class compares the pathname supplied in the argument to the pathname provided in the argument. If the parameter is not null and points to the same file or directory, this function returns true. The operating system determines if the two abstract pathnames are equivalent or not. Syntax: public boolean equals(Object obj) Parameters: obj - The item against which the abstract pathname is to be compared Return Value: It returns true, if and only if the items are the same; otherwise, false. Example: Java // Java program to show the usage of // File Class equals() Method import java.io.File; public class Main { public static void main(String[] args) { boolean bool; try { // create new files File f1 = new File("Gfg.txt"); File f2 = f1; File f3 = new File("Gfg2.txt"); // returns boolean value bool = f1.equals(f2); // prints the output System.out.println("Is is equal : " + bool); // returns boolean value bool = f1.equals(f3); // prints the output System.out.print("Is is equal : " + bool); } catch (Exception e) { // if any error occurs e.printStackTrace(); } } } The method compares two File instances to see whether they are the same. This approach does not compare the content of the file or directory; instead, it checks if the pathnames are the same. Output: Comment S sanketnagare Follow 0 Improve S sanketnagare Follow 0 Improve Article Tags : Java Java-Functions Java-File Class Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings8 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java9 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface4 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like