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