Set a File Writable in Java

An example on setting making a file write-able in Java using File class.


Example


import java.io.File;
class SetFileWritable
{
public static void main(String args[])
{

// Create a File object
File f=new File("SetFileWritable.java");

// It is write-able by default. So set it read-only
f.setReadOnly();

// Print whether it is write able
System.out.println("Is file writable (T/F)? "+f.canWrite());

// Make it writable.
f.setWritable(true);

// Print whether it is writable
System.out.println("Is file writable (T/F)? "+f.canWrite());

}
}

Output


Is file writable (T/F)? false
Is file writable (T/F)? true

Also see my previous post, Set a File Read only in Java 


Posted by at on

Tags: Java IO,