Java IO Tutorial - Java FilePermission(String path, String actions) Constructor








Syntax

FilePermission(String path, String actions) constructor from FilePermission has the following syntax.

public FilePermission(String path,    String actions)

Example

In the following code shows how to use FilePermission.FilePermission(String path, String actions) constructor.

// w  w  w .ja  v  a 2  s .  c  om
import java.io.FilePermission;
import java.io.IOException;
import java.security.PermissionCollection;

public class Main {

  public static void main(String[] args) throws IOException {

    // create new file permissions
    FilePermission  fp = new FilePermission("C://test.txt", "read");

    // create new permission collection
    PermissionCollection  pc = fp.newPermissionCollection();

    // add permission to the permission collection
    pc.add(fp);

    if (pc.implies(new FilePermission("C://test.txt", "read"))) {
      System.out.println("Permission for C://test.txt is read");
    }
  }
}

The code above generates the following result.