Java IO Tutorial - Java File.setWritable(boolean writable)


File.setWritable(boolean writable) has the following syntax.

public boolean setWritable(boolean writable)


In the following code shows how to use File.setWritable(boolean writable) method.

/*  w  w  w  . ja  v a 2  m*/


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

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

    bool = f.canWrite();

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


The code above generates the following result.