在Java中,File.canExecute()究竟做了什么? [英] In Java what exactly does File.canExecute() do?

查看:230
本文介绍了在Java中,File.canExecute()究竟做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个没有执行权限的普通文件但是当我使用这个文件的路径/名称创建一个Java File对象然后调用File.canExecute()时,我得到了结果,而我希望这个方法打电话给假。有人可以解释我在这里缺少的东西吗?

I have created a plain file which does not have execute permission but when I create a Java File object using this file's path/name and then call File.canExecute() I get true as the result, whereas I would expect this method call to return false. Can someone explain what I'm missing here?

Solaris:

$ touch /tmp/nonexecutable
$ ls -l /tmp/nonexecutable
-rw-r--r--   1 root     root           0 May 21 07:48 /tmp/nonexecutable

Java:

String pathName = "/tmp/nonexecutable";
File myFile = new File(pathName);
if (!myFile.canExecute())
{
    String errorMessage = "The file is not executable.";
    log.error(errorMessage);
    throw new RuntimeException(errorMessage);
}

预先感谢您的帮助。

- James

--James

推荐答案

与Java无关 - 你以root身份运行,root是允许一切,无论权限说什么。

Nothing to do with Java - you're running as root, and root is allowed everything, not matter what the permissions say.

这篇关于在Java中,File.canExecute()究竟做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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