Home » Java programming language

Java FilePermission newPermissionCollection() Method with Example

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

FilePermission Class newPermissionCollection() method

  • newPermissionCollection() method is available in java.io package.
  • newPermissionCollection() method is used to instantiates a new PermissionCollection object for storing this (FilePermission) objects.
  • newPermissionCollection() 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.
  • newPermissionCollection() method does not throw an exception at the time of creating an object.

Syntax:

    public PermissionCollection newPermissionCollection();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is PermissionCollection, it returns newly created PermissionCollection object.

Example:

// Java program to demonstrate the example 
// of PermissionCollection newPermissionCollection()
// method of FilePermission

import java.io.*;
import java.security.*;

public class NewPermissionCollectionOfFP {
 public static void main(String[] args) throws Exception {
  FilePermission file_perm = null;

  try {
   // Instantiates FilePermission file_perm
   file_perm = new FilePermission("D:\\includehelp.txt", "read");

   // By using newPermissionCollection() method is to
   // create PermissionCollection object 
   PermissionCollection pc = file_perm.newPermissionCollection();

   // By using add() method is to add
   // the file_perm permissions for pc 
   pc.add(file_perm);

   // By using implies() method is to check
   // whether pc implies the given file_perm
   boolean status = pc.implies(file_perm);
   System.out.println("pc.implies(file_perm): " + status);
  } catch (Exception ex) {
   System.out.println(ex.toString());
  }
 }
}

Output

pc.implies(file_perm): true


Comments and Discussions!

Load comments ↻





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