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








Syntax

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

public boolean setReadable(boolean readable,   boolean ownerOnly)

Example

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

/* www  . j a v  a2  s  .c  o 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, 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.