FilePermission getActions() in Java

getActions(): This method is available in the java.io.FilePermission class of Java.

Syntax:

String java.io.FilePermission.getActions()

This method returns the "canonical string representation" of the actions. That is, this method always returns present actions in the following order: read, write, execute, delete, readlink.

For example, if this FilePermission object allows both write and read actions, a call to getActions will return the string "read,write".

Parameters: NA

Returns: the canonical string representation of the actions.

Exceptions: NA

Approach

Java

import java.io.FilePermission;

public class FilePermissiongetActions {
    public static void main(String[] args) {

        String path = "D:\\hello.txt";
        String actions = "read";
        FilePermission filePermission =
new FilePermission(path, actions);

        System.out.println(filePermission.getActions());
    }
}

Output:

read


Some other methods of FilePermission

equals(Object)This method checks two FilePermission objects for equality. Checks that obj is a FilePermission, and has the same pathname and actions as this object.

FilePermission(String, String)This method creates a new FilePermission object with the specified actions.

getActions()This method returns the "canonical string representation" of the actions.

hashCode()This method returns the hash code value for this object.

implies(Permission)This method checks if this FilePermission object "implies" the specified permission.

newPermissionCollection()This method returns a new PermissionCollection object for storing FilePermission objects.

No comments:

Post a Comment