java files

Java.IO.File canExecute() Code With Examples

Table of Contents

Program

import java.io.*;
public class FileCanExecute 
{
	public static void main(String args[])
	{
		File f = new File("bin");
		if (f.canExecute()) 
                {
			System.out.println("Executable");
		} else 
                {
			System.out.println("Non Executable");
		}
	}
}

Output

Executable

Description

public boolean canExecute()

Tests whether the application can execute 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 execute files that are not marked executable. Consequently this method may return true even though the file does not have execute permissions.

Returns:

true if and only if the abstract pathname exists and the application is allowed to execute the file

Throws:

SecurityException – If a security manager exists and its SecurityManager.checkExec(java.lang.String) method denies execute access to the file