File canRead() method in Java with Examples Last Updated : 11 Jul, 2025 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 A andrew1234 Follow Improve Article Tags : Java Java-Functions Java-IO package Java-File Class Practice Tags : Java Explore BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOPs & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial15+ min readSynchronization in Java10 min readFile Handling in Java5 min readJava Method References9 min readJava 8 Stream Tutorial15+ min readJava Networking15+ min readJDBC Tutorial12 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions7 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like