Home » Java programming language

Java FilePermission getActions() Method with Example

FilePermission Class getActions() method: Here, we are going to learn about the getActions() method of FilePermission Class with its syntax and example.
Submitted by Preeti Jain, on April 02, 2020

FilePermission Class getActions() method

  • getActions() method is available in java.io package.
  • getActions() method is used to check whether this FilePermission and the given object are equal or not in terms of pathname and actions like read, write, delete, execute, delete, etc.
  • getActions() 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.
  • getActions() method does not throw an exception at the time of getting actions.

Syntax:

    public String getActions();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is String, it returns the canonical (some authorised) denotations of the actions.

Example:

// Java program to demonstrate the example 
// of String getActions() method 
// of FilePermission

import java.io.*;

public class GetActionsOfFP {
 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 getActions() method is to return
   // the action performed on the file of the 
   // FilePermission
   String action = fp1.getActions();
   System.out.println("fp1.getActions(): " + action);

   action = fp2.getActions();
   System.out.println("fp2.getActions(): " + action);

  } catch (Exception ex) {
   System.out.println(ex.toString());
  }
 }
}

Output

fp1.getActions(): read
fp2.getActions(): write



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.