FilePermission newPermissionCollection() in Java

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

Syntax:

PermissionCollection java.io.FilePermission.newPermissionCollection()

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

FilePermission objects must be stored in a manner that allows them to be inserted into the collection in any order, but that also enables the PermissionCollection implies method to be implemented in an efficient (and consistent) manner.

Parameters: NA

Returns: a new PermissionCollection object suitable for storing FilePermissions.

Exceptions: NA

Approach

Java

import java.io.FilePermission;

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

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

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

Output:

java.io.FilePermissionCollection@4d591d15 (

)


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