Home »
Java programming language
Java FilePermission implies() Method with Example
FilePermission Class implies() method: Here, we are going to learn about the implies() method of FilePermission Class with its syntax and example.
Submitted by Preeti Jain, on April 02, 2020
FilePermission Class implies() method
- implies() method is available in java.io package.
- implies() method is used to check whether this FilePermission implies the given permission (perm) or not.
- implies() 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.
- implies() method does not throw an exception at the time of implies the given permission.
Syntax:
public boolean implies(Permission perm);
Parameter(s):
- Permission perm – represents the permission object to be checked.
Return value:
The return type of the method is boolean, it returns true based on some statements:
- When the given permission object is an instance of FilePermission.
- When the given permission actions are a proper subset of this FilePermission object actions.
- When the pathname of the given permission object is implied by this FilePermission object pathname.
- Otherwise, it returns false.
Example:
// Java program to demonstrate the example
// of boolean implies(Permission perm) method
// of FilePermission
import java.io.*;
public class ImpliesOfFP {
public static void main(String[] args) throws Exception {
FilePermission fp1 = null;
FilePermission fp2 = null;
try {
// Instantiates FilePermission fp1 , fp2
fp1 = new FilePermission("D:\\includehelp.txt", "read");
fp2 = new FilePermission("D:\\includehelp.txt", "write");
// By using implies() method is to check
// whether this FilePermission implies the
// given permission or not
boolean status = fp1.implies(fp1);
System.out.println("fp1.implies(fp1): " + status);
status = fp2.implies(fp1);
System.out.println("fp2.implies(fp1): " + status);
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
}
Output
fp1.implies(fp1): true
fp2.implies(fp1): false