How to make a file read only in java

Previous
Next
In this post, we will see how to make a read only file in java. It is very simple. You need to just call java.io.File ‘s ¬†setReadOnly() method.

1) How to make a file read only

Java program:

When you run above program, you will get following output:

2) How to make it writable  again

If you have made file read only, you can make file writable again by using method setWritable(true).
This method is introduced in java 1.6.


Java program:

When you run above program, you will get following output:

 

Previous
Next

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.

Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog