是否有一种很好的方法来确定文件是否可以在Java中执行 [英] Is there a good way to determine if a file is executable in Java

查看:76
本文介绍了是否有一种很好的方法来确定文件是否可以在Java中执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你可以打电话

Runtime.getRuntime().exec(file);

并且如果它不可执行则会得到异常,但这是不安全的,因为运行可执行文件可以有边效果。

and get an exception if it is not executable, however this is unsafe since running an executable can have side effects.

我想在Windows上检查扩展名已经足够了,但有没有办法可以读取* nix文件系统上的可执行文件位?

I guess just checking the extension is enough on Windows, but is there a way I can read the executable bit on *nix file systems?

找出文件在OS中是否可执行的最佳方法是什么?

What is the best way to find out if an file is executable in the OS?

推荐答案

请参见 java.io. File.canExecute()

这篇关于是否有一种很好的方法来确定文件是否可以在Java中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆