Check if file can be read in Java

An example on checking whether a file can be read or not in Java using File class.


Example


import java.io.File;
class CheckRead
{
public static void main(String args[])
{

// Create a File object
File f=new File("CheckRead.java");

// Check can be Read
System.out.println("Can file be read (T/F)? "+f.canRead());

}
}

Output


Can file be read (T/F)? true

No comments: