Java FilePermission implies() Example
FilePermission class implies() method example. This example shows you how to use implies() method.
Syntax is : public boolean implies(Permission p)
This method checks if this FilePermission object "implies" the specified permission.
Some conditions in which, this method returns true if:
* p is an instanceof FilePermission,
* p's actions are a proper subset of this object's actions
Here is the code.
/**
* @(#) ImpliesFilePermission.java
* A class representing use of method implies() of FilePermission
class in java.io Package.
* @Version 09-June-2008
* @author Rose India Team
*/
import java.io.*;
import javax.management.*;
public class ImpliesFilePermission {
public static void main(String[] args){
// create object of FilePermission class.
FilePermission objFP1 = new FilePermission("Mahendra.txt","read");
FilePermission objFP2 = new FilePermission("Mahendra.txt","write");
FilePermission objFP3 = new FilePermission("file.txt","execute");
FilePermission objFP4 = new FilePermission("Mahendra.txt","read");
//Check,if this FilePermission object "implies" the specified permission.
boolean bool = objFP1.implies(objFP2);
System.out.println("objFP1 object implies the objFP2 ......." + bool);
bool = objFP1.implies(objFP4);
System.out.println("objFP1 object implies the objFP4 ......." + bool);
bool = objFP2.implies(objFP3);
System.out.println("objFP2 object implies the objFP3 ......." + bool);
bool = objFP1.implies(objFP3);
System.out.println("objFP1 object implies the objFP3 ......." + bool);
}
} |
Output of the program.
objFP1 object implies the objFP2 .......false
objFP1 object implies the objFP4 .......true
objFP2 object implies the objFP3 .......false
objFP1 object implies the objFP3 .......false |
|