File canExecute() method in Java with Examples Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report The canExecute() function is a part of File class in Java. This function determines whether the program can execute the specified file denoted by the abstract pathname. If the file path exists and the application is allowed to execute the file, this method will return true. Else it will return false. Function signature: public boolean canExecute() Syntax: file.canExecute(); Parameters: This function does not accept any parameter. Return Value: This function returns a boolean value representing whether the specified file can be executed or not. Exceptions: This method throws Security Exception if the read access to the file is denied Below programs illustrates the use of canExecute() function: Example 1: The file "F:\\program.txt" is an existing file in F: directory and the program is allowed the permission to execute the file. Java // Java program to demonstrate // canExecute() method of File class import java.io.*; public class solution { // Driver Code public static void main(String args[]) { // Get the file to be executed File f = new File("F:\\program.txt"); // Check if this file // can be executed or not // using canExecute() method if (f.canExecute()) { // The file is can be executed // as true is returned System.out.println("Executable"); } else { // The file is cannot be executed // as false is returned System.out.println("Non Executable"); } } } Output: Executable Example 2: The file "F:\\program1.txt" does not exist we will try to check if the file is executable or not. CPP // Java program to demonstrate // canExecute() method of File class import java.io.*; public class solution { // Driver Code public static void main(String args[]) { // Get the file to be executed File f = new File("F:\\program1.txt"); // Check if this file // can be executed or not // using canExecute() method if (f.canExecute()) { // The file is can be executed // as true is returned System.out.println("Executable"); } else { // The file is cannot be executed // as false is returned System.out.println("Non Executable"); } } } Output: Non Executable 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 canExecute() 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 File canWrite() method in Java with examples The canWrite()function is a part of File class in Java . This function determines whether the program can write the file denoted by the abstract path name.The function returns true if the abstract file path exists and the application is allowed to write the file. Function signature: public boolean c 2 min read File delete() method in Java with Examples The delete() function is a part of File class in Java . This function deletes an existing file or directory. If the file is deleted then the function returns true else returns false Function signature: public boolean delete() Syntax: boolean var = file.delete(); Parameters: This method does not acce 2 min read Files delete() method in Java with Examples The delete() method of java.nio.file.Files help us to delete a file located at the path passed as a parameter. This method may not be atomic with respect to other file system operations. If the file is a symbolic link then the symbolic link itself, not the final target of the link, is deleted. If th 3 min read File canRead() method in Java with Examples 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 ca 2 min read File createNewFile() method in Java with Examples The createNewFile() function is a part of File class in Java . This function creates new empty file. The function returns true if the abstract file path does not exist and a new file is created. It returns false if the filename already exists. Function signature: public boolean createNewFile() Synta 2 min read Like