Many times we may want to check whether a particular file is executable. You many need to trigger a script or an exe. In case it is important to know whether the file is executable before running it. We can use the canExecute() method of the File class for this purpose. This method is available since java 1.6.
package com.javahash.file; import java.io.File; public class ExecuteFileTest { public static void main(String[] args) { File f=new File("abc.sh"); if(f.canExecute()){ System.out.println("Executable file"); }else{ System.out.println("Not an Executable file"); } } }
The post How to check a file is executable in java appeared first on Java Hash.