Is there a good way to determine if a file is executable in Java

后端 未结 3 2083
有刺的猬
有刺的猬 2020-12-16 19:27

I\'m aware you can call

Runtime.getRuntime().exec(file);

and get an exception if it is not executable, however this is unsafe since runnin

相关标签:
3条回答
  • 2020-12-16 19:52

    See java.io.File.canExecute()

    0 讨论(0)
  • 2020-12-16 20:08

    The class java.io.File has method canExecute().

    0 讨论(0)
  • 2020-12-16 20:18

    You can use Files class. It has this method static boolean isExecutable(Path path). If you have just a String of path then you can get Path using Paths class. Like this

    Path path = Paths.get(pathToFile);
    
    0 讨论(0)
提交回复
热议问题