File setExecutable(boolean) in Java

setExecutable(boolean): This method is available in the java.io.File class of Java.

Syntax:

boolean java.io.File.setExecutable(boolean executable)

This method takes one argument. This method is a convenient method to set the owner's execute permission for this abstract pathname.

Parameters: One parameter is required for this method.

executable: If true, sets the access permission to allow execute operations; if false disallow execute operations.

Returns: true if and only if the operation succeeded.

Throws:

SecurityException - If a security manager exists and its java.lang.SecurityManager.checkWrite(java.lang.String) method denies write access to the file.

Approach

Java

import java.io.File;

public class FilesetExecutable {
    public static void main(String[] args) {

        String pathname = "D:\\hello.txt";
        File file = new File(pathname);

        boolean executable = true;

        System.out.println(file.setExecutable(executable));
    }
}

Output:

true


No comments:

Post a Comment