Program
import java.io.*; public class FileCanRead { public static void main(String args[]) { File f = new File("bin"); if (f.canRead()) { System.out.println("Can be Read"); } else{ System.out.println("Cannot be Read"); } } }
Output
Can be Read
Description
public boolean canRead()
Tests whether the application can read the file denoted by this abstract pathname. On some platforms it may be possible to start the Java virtual machine with special privileges that allow it to read files that are marked as unreadable. Consequently this method may return true even though the file does not have read permissions.
Returns:
true if and only if the file specified by this abstract pathname exists and can be read by the application; false otherwise
Throws:
SecurityException – If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file