File class canRead()method example
Tests whether the application can read the file
File class canRead()method example. This example shows you how to use canRead()method.This method Tests whether the application can read the file denoted by this abstract pathname.
Here is the code:-
/**
* @Program that Tests whether the application can read the file denoted by
this abstract pathname.
* CanRead.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class CanRead {
public static void main(String[] args) {
// Create a File object
File myFile = new File("/home/girish/Desktop/g.txt");
//Tests whether the application can read the file
if(myFile.canRead())
{
System.out.println(myFile.getAbsolutePath()+" is a readable File");
}
else
{
System.out.println(myFile.getAbsolutePath()+ "is not a readable File");
}
}
} |
Output of the program:-
| /home/girish/Desktop/g.txt is a readable File |
|