File canRead() method in Java with Examples Last Updated : 22 Sep, 2020 Comments Improve Suggest changes Like Article Like Report The canRead()function is a part of the File class in Java. This function determines whether the program can read the file denoted by the abstract pathname. The function returns true if the abstract file path exists and the application is allowed to read the file.Function signature: public boolean canRead() Syntax: file.canRead() Parameters: This method does not accept any parameter.Return Value: The function returns a boolean value representing whether the application is allowed to read the file or not.Exception: This method throws Security Exception if the read access to the file is denied. Below programs illustrates the use of canRead() function: Example 1: The file "F:\\program.txt" is readable Java // Java program to demonstrate // canRead() method of File Class import java.io.*; public class solution { public static void main(String args[]) { // Get the file File f = new File("F:\\program.txt"); // Check if the specified file // can be read or not if (f.canRead()) System.out.println("Can be Read"); else System.out.println("Cannot be Read"); } } Output: Can be Read Example 2: The file "F:\\program1.txt" is NOT readable Java // Java program to demonstrate // canRead() method of File Class import java.io.*; public class solution { public static void main(String args[]) { // Get the file File f = new File("F:\\program1.txt"); // Check if the specified file // can be read or not if (f.canRead()) System.out.println("Can be Read"); else System.out.println("Cannot be Read"); } } Output: Cannot be Read Note: The programs might not run in an online IDE. Please use an offline IDE and set the path of the file. Comment More infoAdvertise with us Next Article File canRead() method in Java with Examples A andrew1234 Follow Improve Article Tags : Java Java-Functions Java-IO package Java-File Class Practice Tags : Java Similar Reads Files copy() Method in Java with Examples The copy() method of java.nio.file.Files Class is used to copy bytes from a file to I/O streams or from I/O streams to a file. I/O Stream means an input source or output destination representing different types of sources e.g. disk files. Methods: Based on the type of arguments passed, the Files cla 5 min read FileInputStream close() Method in Java with Examples FileInputStream class is helpful to read data from a file in the form of a sequence of bytes. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader. FileInputStream.close() method After any operation to the file, w 2 min read File setReadOnly() method in Java with examples The setReadOnly() method is a part of File class. The setReadOnly() function marks the specified file or directory such that only read operations are allowed on the file or directory. Function Signature: public boolean setReadOnly() Syntax: file.setReadOnly() Parameters: The function do not requires 2 min read Files isReadable() method in Java with Examples isReadable() method of java.nio.file.Files help us to check whether Java virtual machine has appropriate privileges that would allow it to open this file for reading or not. This method test file is readable or not. This method checks that a file exists or not and if file exists then it is readable 2 min read FileInputStream available() Method in Java with Examples The available() method of FileInputStream class is used to return the estimated number of remaining bytes that can be read from the input stream without blocking. This method returns the number of bytes remaining to read from the file. When a file is completely read, this function returns zero. Synt 3 min read Like