equals(Object): This method is available in the java.io.File class of Java.
Syntax:
boolean java.io.File.equals(Object obj)
This method takes one argument. This method 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.
Note: On UNIX systems, the alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.
Parameters: One parameter is required for this method.
obj: The object to be compared with this abstract pathname
Returns: true if and only if the objects are the same; false otherwise.
Exceptions: NA
Approach
Java
import java.io.File;public class Fileequals {public static void main(String[] args) {String pathname = "D:\\hello.txt";File file = new File(pathname);File obj = new File(pathname);System.out.println(file.equals(obj));}}
Output:
true
No comments:
Post a Comment