Published September 1st, 2008
File Read Only in JDK6
This is a good feature for all those developer who do a lot of file reading, writing stuff. Java SE 6.0 gives us the feature to set file read only. There are lot of place where its correct and valid to set file as read only rather than leaving it read-write. Like you are writing some version repository or some file that should not be changed.
Here is a small code to change the file read mode:
import java.io.File;
import java.io.IOException;
public class FileReadOnly {
public static void main(String[] args) throws IOException {
File file = new File(”test.txt”);
file.createNewFile();
System.out.println(”Before. canWrite?” + file.canWrite());
file.setWritable(false);
System.out.println(”After. canWrite?” + file.canWrite());
}
}
So, from next time don’t forget to use this.











Java,JavaScript,Threading,
Optimization and more with Vaibhav 


