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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.