Java FilePermission equals() Example

FilePermission class equals() method example. This example shows you how to use equals() method.


Syntax is : public boolean equals(Object obj)
This method checks two FilePermission objects for equality. Checks that obj is a FilePermission, and has the same pathname and
actions as this object.

Here is the code.
/**
 * @(#) EqualsFilePermission.java
 * A class representing use of method equals() of FilePermission 
class in java.io Package.
 * @Version  08-June-2008
 @author   Rose India Team
 */
import java.io.*;

public class EqualsFilePermission {

    public static void main(String[] argsthrows IOException {
    
      // create object of FilePermission class.
        FilePermission objFP1 = new FilePermission("Mahendra.txt","read");
      FilePermission objFP2 = new FilePermission("Mahendra.txt","write");
      FilePermission objFP3 = new FilePermission("file.txt","read");
      FilePermission objFP4 = new FilePermission("Mahendra.txt","read");

      // check for eqality between two objects of FilePermission class.
    boolean bool = objFP1.equals(objFP2);
        System.out.println("objFP1 is equal to objFP2 ........" + bool);
    bool = objFP1.equals(objFP3);
        System.out.println("objFP1 is equal to objFP2 ........" + bool);
    bool = objFP2.equals(objFP3);
        System.out.println("objFP2 is equal to objFP3 ........" + bool);
    bool = objFP1.equals(objFP4);
        System.out.println("objFP1 is equal to objFP4 ........" + bool);
  }
}

Output of the program.
objFP1 is equal to objFP2 ........false
objFP1 is equal to objFP2 ........false
objFP2 is equal to objFP3 ........false
objFP1 is equal to objFP4 ........true

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US