setExecutable(boolean, boolean): This method is available in the java.io.File class of Java.
Syntax:
boolean java.io.File.setExecutable(boolean executable, boolean ownerOnly)
This method takes two arguments. This method sets the owner's or everybody's executing permission for this abstract pathname.
Parameters: Two parameters are required for this method.
executable: If true, sets the access permission to allow execute operations; if false disallow execute operations.
ownerOnly: If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody.
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 FilesetExecutable2 {public static void main(String[] args) {String pathname = "D:\\hello.txt";File file = new File(pathname);boolean executable = true, ownerOnly = false;System.out.println(file.setExecutable(executable, ownerOnly));}}
Output:
true
No comments:
Post a Comment