Java IO Tutorial - Java File.setReadable(boolean readable)


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

public boolean setReadable(boolean readable)


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

// ww w.j  av a 2  s .c  o m

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.