Java File.setReadable(boolean readable) example

 Posted On  | Pooja Lakkihal 

In this java tutorial, You will learn how to set the owner's read permission to read this abstract pathname file. Java File.setReadable() method returns true if and only if the operation succeeded.

This method sets the owner's read permission for this abstract pathname.

syntax

public boolean setReadable(boolean readable)

Parameters

readable - If true, sets the access permission to allow read operations; if false to disallow read operations.

Returns

true if and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If readable is false and the underlying file system does not implement a read permission, then the operation will fail.

Throws

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

Java File setReadable(boolean readable) example

  • Create File instance new File("C:\\technicalkeeda\\hello.txt");
  • file.setReadable(true) Set the file to readable by keeping true.
  • file.canRead() Check if file can be readable.
package com.technicalkeeda;

import java.io.File;

public class App {

    public static void main(String[] args) {

        File file = new File("C:\\technicalkeeda\\hello.txt");

        System.out.println(file + " :- Is this file set to readable ?  " + file.setReadable(true));

        System.out.println(file + " :- Can you read in this file ?  " + file.canRead());

    }

}

output

C:\technicalkeeda\hello.txt :- Is this file set to readable ?  true

C:\technicalkeeda\hello.txt :- Can you read in this file ?  true


© technicalkeeda.com 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0408 seconds.