I’m looking for a way to check if a file is executable with Java 1.5.
I found SecurityManager.checkExec but I don’t think it helps…
I’m currently on Linux, but this needs to work for Windows also.
Any help would be appreciated, Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
SecurityManager.checkExecactually checks something else, it checks whether your JVM has sufficent permissions to launch an executable.You want
java.nio.file.Files.isExecutable(...)to see if the file is considered “executable”.It is available only in Java 1.7. For 1.5 and later, you would typically construct a
ProcessBuilderclass and and capture exceptions on failure to execute the file. For prior to 1.5, you would use theRuntime.exec(...)and capture the exception to determine that the file wasn’t executable.