boolean equals(Object obj)


描述

所述java.io.FileOutputStream.equals(Object OBJ)方法检查是否相等2个FilePermission对象。验证obj是否为FilePermission,并且具有与此对象相同的路径名和操作。

声明

以下是java.io.FilePermission.equals(Object obj)方法的声明

public boolean equals(Object obj)

参数

obj - 要与此对象进行相等性测试的对象。

返回值

如果obj是FilePermission,并且该路径名和操作与此对象相同,则此方法返回true。

异常

NA

实例

以下示例显示了java.io.FilePermission.equals(Object obj)方法的用法。

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 {

      }
   }
}

让我们编译并运行上面的程序,这将产生以下结果

false
false
true