Java.io.FilePermission.implies() Method



Description

The java.io.FileOutputStream.implies(Permission p) method tests if this FilePermission object "implies" the specified permission.

The method returns true if −

  • p is an instance of file permission.
  • Actions of p are a proper subset of this object's action.
  • Pathname of p is implied by this object's pathname.

Declaration

Following is the declaration for java.io.FilePermission.implies(Permission p) method −

public boolean implies(Permission p)

Parameters

p − permission to check against.

Return Value

This method returns true if the specified permission is not null and is implied by this object, else false.

Exception

NA

Example

The following example shows the usage of java.io.FilePermission.implies(Permission p) 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://test.txt", "write");
         fp2 = new FilePermission("C://test1.txt", "read");
         fp3 = new FilePermission("C://test.txt", "read");
         
         // tests if implied by this object
         bool = fp.implies(fp1);
         
         // print
         System.out.println(bool);
         
         bool = fp.implies(fp2);
         System.out.println(bool);
         
         bool = fp.implies(fp3);
         System.out.print(bool);
         
      } catch(Exception ex) {
         // if an error occurs
         ex.printStackTrace();
      }
   }
}

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

false
false
true
java_io_filepermission.htm
Advertisements