File SetReadOnly() Example
Marks the file or directory named by this abstract pathname so that only read operations are allowed.
File class SetReadOnly() method example. This example shows you how to use SetReadOnly method.This method Marks the file or directory named by this abstract pathname so that only read operations are allowed.
Here is the code:-
/**
* @Program that Marks the file or directory named by this abstract pathname
* so that only read operations are allowed.
* SetReadOnly.java
* Author:-RoseIndia Team
* Date:-31-May-2008
*/
import java.io.*;
public class SetReadOnly {
public static void main(String[] args) {
File f = new File("/home/girish/Desktop/girish.txt");
if (f.exists()) {
boolean b = f.setReadOnly();
System.out.println("read operations are allowed : "+b);
} else {
System.out.println("File cannot exists: ");
}
}
} |
Output of the Program
| read operations are allowed : true |
|