file equals Example
file class equals example. This example shows you how to use equals method.
File class equals example. method generates boolean results after testing two File class objects on the specified abstract pathname.path is abstract as it is defined inside the system.method is being called by a File class object.
This method works differently on different systems, on UNIX based System alphabetic cases are significant in this method where as on windows it is not.
Here is the code:-
/**
* @Program uses equals method to check the equality of two File class objects
* and generates boolean results
* Equals.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.*;
public class Equals {
public static void main(String args[]) {
File triangle = new File("/home/mahendra/Desktop/baadshah");
File baadshah = new File("/home/mahendra/Desktop/baadshah");
File kronze = new File("/home/mahendra/Desktop/main");
triangle.equals(baadshah);
if (triangle.equals(baadshah) == true)
System.out.println("Both File objects are equal: " + true);
if (triangle.equals(kronze) == true)
System.out.println("Both File objects are equal: " + true);
else
System.out.println("Operation failed: " + false);
}
} |
Output of the program:-
Both File objects are equal: true
Operation failed: false |
|