file canRead Example
file class canRead example. This example shows you how to use canRead method.
File class canRead example. method generates boolean results after checking the reading permission made by the owner of file or directory on the specified abstract pathname.path is abstract as it is defined inside the system.method is being called through a File class object.
Here is the code:-
/**
* @Program checks the readable permission programmed in files or directories
* and generates booleans results.
* CanRead.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.*;
public class CanRead {
public static void main(String args[]) {
File patent = new File("/home/mahendra/Desktop/predator.org");
patent.setReadable(false);
boolean result = patent.canRead();
if (result == true)
System.out.println("Reading access granted: " + result);
else
System.out.println("Reading access denied: " + result);
patent.setReadable(true);
result = patent.canRead();
if (result == false)
System.out.println("Reading access denied: " + result);
else
System.out.println("Reading access granted: " + result);
}
}
|
Output of the program:-
Reading access denied: false
Reading access granted: true |
|