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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.