在Java中,File.canExecute()究竟做了什么?

Jam*_*ams 4 java io permissions file

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

Solaris上:

$ touch /tmp/nonexecutable
$ ls -l /tmp/nonexecutable
-rw-r--r--   1 root     root           0 May 21 07:48 /tmp/nonexecutable
Run Code Online (Sandbox Code Playgroud)

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);
}
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助.

- 詹姆士

Mic*_*rdt 5

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

  • 该文件由root.root拥有,它刚刚创建,表明OP以root身份运行 (3认同)