Home » Java programming language

Java FilePermission equals() Method with Example

FilePermission Class equals() method: Here, we are going to learn about the equals() method of FilePermission Class with its syntax and example.
Submitted by Preeti Jain, on April 02, 2020

FilePermission Class equals() method

  • equals() method is available in java.io package.
  • equals() method is used to check whether this FilePermission and the given object are equal or not in terms of pathname and actions.
  • equals() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • equals() method does not throw an exception at the time of checking the equality of two objects.

Syntax:

    public boolean equals(Object ob);

Parameter(s):

  • Object ob – represents the object to be checked for equality with this object.

Return value:

The return type of the method is boolean, it returns true when both compared object are equal otherwise it returns false.

Example:

// Java program to demonstrate the example 
// of boolean equals(Object ob) method 
// of FilePermission

import java.io.*;

public class EqualsOfFP {
 public static void main(String[] args) throws Exception {
  FilePermission file1_perm = null;
  FilePermission file2_perm = null;

  try {
   // Instantiates FilePermission file1_perm , file2_perm 
   file1_perm = new FilePermission("D:\\includehelp.txt", "read");
   file2_perm = new FilePermission("D:\\includehelp.txt", "write");

   // By using equals() method is to check
   // whether the file permissions on the given file
   // are same or not i.e true for same otherwise false
   boolean status = file1_perm.equals(file2_perm);
   System.out.println("file1_perm .equals(fp2_stm): " + status);
  } catch (Exception ex) {
   System.out.println(ex.toString());
  }
 }
}

Output

file1_perm .equals(fp2_stm): false



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.