Java File canExecute() method example

HQ ¬Ľ Java Tutorial ¬Ľ java.io ¬Ľ File ¬Ľ canExecute() method example
Java File canExecute() method example 2018-02-16T07:26:45+00:00

java.io.File canExecute()

Description

On this document we will be showing a java example on how to use the canExecute() method of File Class. This method is basically a check if the file can be executed. 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.

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

Method Syntax

public boolean canExecute()

Method Argument

Data Type Parameter Description
N/A N/A N/A

Method Returns

This method returns boolean, true if and only if the abstract pathname exists and the application is allowed to execute the file

Compatibility

Requires Java 1.0 and up

Java File canExecute() Example

Below is a java code demonstrates the use of canExecute() method of File class. The example presented might be simple however it shows the behaviour of the canExecute() method. Basically we initialize a new File object that corresponds to a physical file which does have permission for execution and then the canExecute() method is used to check if the input file can be executed.

Sample Output

Below is the sample output when you run the above example.

java lang File canExecute() example output

Contact Info

Singapore

Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close