File setReadable(boolean) in Java

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

Syntax:

boolean java.io.File.setReadable(boolean readable)

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

Parameters: One parameter is required for this method.

readable: If true, sets the access permission to allow read operations; if false disallow read 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 FilesetReadable {
    public static void main(String[] args) {

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

        boolean readable = true;

        System.out.println(file.setReadable(readable));
    }
}

Output:

true


No comments:

Post a Comment