A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/java-io-filepermission-class-java/ below:

Java FilePermission Class - GeeksforGeeks

Java FilePermission Class

Last Updated : 10 Jan, 2025

java.io.FilePermission class represents access to a file or directory. These accesses are in the form of a path name and a set of actions associated with the path name(specifies which file to open along with the extension and the path).

Example: In FilePermission("GEEKS.txt", "read") "GEEKS.txt" is the path, and "read" is the action being performed.

Supported Actions:

Class Declaration of FilePermission Class

public final class FilePermission
extends Permission
implements Serializable

Constructor of FilePermission Class 

FilePermission(String p, String a): Creates a new file permission object with "a" action.

Methods of FilePermission Class 1. equals(Object FP_obj)

Syntax:

public boolean equals(Object FP_obj)

Example: 

Java
// Java Program illustrating equals() method
import java.io.*;

public class EqualsMethod
{
    public static void main(String[] args) throws IOException
    {
        boolean bool = false;

        // Creating new FilePermissions("Path", "action")
        FilePermission FP_obj1 = new FilePermission("GEEKS", "read");
        FilePermission FP_obj2 = new FilePermission("ABC", "write");
        FilePermission FP_obj3 = new FilePermission("GEEKS", "read");

        // Use of equals method 
        bool = FP_obj2.equals(FP_obj1);
        System.out.println("Whether FP_obj1 equals FP_obj2 : " + bool);

        bool = FP_obj2.equals(FP_obj3);
        System.out.println("Whether FP_obj2 equals FP_obj2 : " + bool);

        bool = FP_obj1.equals(FP_obj3);
        System.out.println("Whether FP_obj3 equals FP_obj1 : " + bool);

    }
}

Output: 

2. getActions()

Syntax:

public String getActions()

Returns: Canonical string: representing the actions associated with the object.

Example: 

Java
// Java Program illustrating getActions() method
import java.io.*;

public class GetActions
{
    public static void main(String[] args) throws IOException
    {
        // Creating new FilePermissions
        FilePermission FP_obj1 = new FilePermission("GEEKS", "read, delete, write");
        FilePermission FP_obj2 = new FilePermission("ABC", "write, read, execute");
        FilePermission FP_obj3 = new FilePermission("GEEKS", "delete, readlink, read");

        // Use of getActions() method 
        String str = FP_obj1.getActions();
        System.out.println("Actions with FP_obj1 : " + str);

        str = FP_obj2.getActions();
        System.out.println("Actions with FP_obj2 : " + str);

        str = FP_obj3.getActions();
        System.out.println("Actions with FP_obj3 : " + str);

    }
}

Output: 

3. hashCode()

Syntax:

public int hashCode()

Returns: hash code value for the argumented object

Example: 

Java
// Java Program illustrating hashCode() method
import java.io.*;

public class HashCodeMethod
{
    public static void main(String[] args) throws IOException
    {
        // Creating new FilePermissions
        FilePermission FP_obj1=new FilePermission("GEEKS", "read, delete, write");

        // Use of hashCode() method
        int i = FP_obj1.hashCode();

        System.out.println("hashCode value for FP_obj1 : " + i);

    }
}

Output: 

4. implies(Permission arg)

Syntax:

public boolean implies(Permission arg)

Example: 

Java
// Java Program illustrating implies() method
import java.io.*;

public class ImpliesMethod
{
    public static void main(String[] args) throws IOException
    {
        // Creating new FilePermissions
        FilePermission FP_obj1 = new FilePermission("GEEKS", "read");
        FilePermission FP_obj2 = new FilePermission("ABC", "write");
        FilePermission FP_obj3 = new FilePermission("GEEKS", "delete");

        // Use of implies() method

        boolean check = FP_obj1.implies(FP_obj2);
        System.out.println("Using implies() for FP_obj1 : " + check);
                

        // Checked here with the same FilePermission object
        check = FP_obj2.implies(FP_obj2);
        System.out.println("Using implies() for FP_obj2 : " + check);
        
    }
}

Output: 

5. newPermissionCollection()

Syntax:

public PermissionCollection newPermissionCollection()

Example: 

Java
// Java Program illustrating 
// newPermissionCollection() method
import java.io.*;
import java.security.PermissionCollection;

public class NewPermissionCollection
{
    public static void main(String[] args)
      					throws IOException
    {
        // Creating new FilePermissions
        FilePermission FP_obj1 = new FilePermission("GEEKS.txt", "read");
        
        // Creating new PermissionCollection
        // Use of newPermissionCollection() 
        PermissionCollection FP = FP_obj1.newPermissionCollection();
        
        // Collecting the Permissions of FP_obj1 for FP
        FP.add(FP_obj1);
        
        boolean check = FP.implies(new FilePermission("GEEKS.txt", "read"));
        System.out.println("Is newPermissionCollection() working : " + check);

    }
}

Output: 



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4