Java File.setReadable(boolean readable)

Syntax

File.setReadable(boolean readable) has the following syntax.

public boolean setReadable(boolean readable)

Example

In the following code shows how to use File.setReadable(boolean readable) method.


/*from   w  w w.  ja  va 2 s.  co m*/
import java.io.File;

public class Main {
  public static void main(String[] args) {
    File f = new File("C:/test.txt");

    // set read permission
    boolean bool = f.setReadable(true);

    System.out.println("setReadable() succeeded?: " + bool);

    // checks whether the file is readable
    bool = f.canRead();

    System.out.print("Is file readable?: " + bool);

  }
}

The code above generates the following result.