A RetroSearch Logo

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

Search Query:

Showing content from https://www.tutorialspoint.com/java/util/java_util_propertypermission.htm below:

Java PropertyPermission Class

Java PropertyPermission Class Introduction

The Java PropertyPermission class is a class for property permissions. Following are the important points about PropertyPermission −

Class declaration

Following is the declaration for java.util.PropertyPermission class −

public final class PropertyPermission
   extends BasicPermission
Class constructors Sr.No. Constructor & Description 1

PropertyPermission(String name, String actions)

This creates a new PropertyPermission object with the specified name.

Class methods Methods inherited

This class inherits methods from the following classes −

Checking a PropertyPermission Object for read/write actions Example

The following example shows the usage of Java PropertyPermission getActions() method to check a permission object. We've built a PropertyPermission object, and then check the permission to be read or write.

package com.tutorialspoint;

import java.util.PropertyPermission;

public class PropertyPermissionDemo {
   private static PropertyPermission permission;
   
   public static void main(String[] args) {

      // Build property permissions
      permission = new PropertyPermission("java.home.*", "read,write");

      // Check permissions
      checkFilePermissions("java.home.usr");
   }

   private static void checkFilePermissions(String path) {
      
      // Check permission given name
      if(path.matches(permission.getName())) {

         // Get actions list
         String actions = permission.getActions();
         
         // Match read write actions
         if(actions.contains("read"))
         System.out.println("Has permissions on "+path+" for read");
         
         if(actions.contains("write"))
         System.out.println("Has permissions on "+path+" for write");
      }
   }
}
Output

Let us compile and run the above program, this will produce the following result −

Has permissions on java.home.usr for read
Has permissions on java.home.usr for write

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