Java.io.FilePermission.equals() Method



Description

The java.io.FileOutputStream.equals(Object obj) method checks two FilePermission objects for equality. Verifies that obj is a FilePermission, and has the same pathname and actions as this object.

Declaration

Following is the declaration for java.io.FilePermission.equals(Object obj) method −

public boolean equals(Object obj)

Parameters

obj − The object to be tested for equality with this object.

Return Value

This method returns true if the obj is a FilePermission, and has the same pathname and actions as this object.

Exception

NA

Example

The following example shows the usage of java.io.FilePermission.equals(Object obj) method.

package com.tutorialspoint;

import java.io.FilePermission;
import java.io.IOException;

public class FilePermissionDemo {
   public static void main(String[] args) throws IOException {
      FilePermission fp = null;
      FilePermission fp1 = null;
      FilePermission fp2 = null;
      FilePermission fp3 = null;
      boolean bool = false;
      
      try {
         // create new file permissions
         fp = new FilePermission("C://test.txt", "read");
         fp1 = new FilePermission("C://test1.txt", "read");
         fp2 = new FilePermission("C://test.txt", "write");
         fp3 = new FilePermission("C://test.txt", "read");
         
         // checks two file permission objects for equality
         bool = fp.equals(fp1);

         // prints
         System.out.println(bool);
         
         // checks two file permission objects for equality
         bool = fp.equals(fp2);
         
         // prints
         System.out.println(bool);
         
         // checks two file permission objects for equality
         bool = fp.equals(fp3);
         
         // prints
         System.out.print(bool);
         
      } catch(Exception ex) {
         // if an error occurs
         ex.printStackTrace();
      } finally {
         
      }
   }
}

Let us compile and run the above program, this will produce the following result −

false
false
true
java_io_filepermission.htm
Advertisements