Java:什么构成“正常” File.isFile()的上下文中的文件? [英] Java: What constitutes a "normal" file in the context of File.isFile()?

查看:257
本文介绍了Java:什么构成“正常” File.isFile()的上下文中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了file.isFile()返回false的情况,这表明文件不是正常的。但是,我无法找到正常含义的定义。文档链接到Oracle 状态:


如果文件不是目录,并且符合其他系统相关标准,则该文件是正常的。


该文件由 _www:staff 拥有,并具有权限 - RW-R - R的 - 。该目录也由 _www:staff 拥有,并具有权限 drwxrw -r - 。正在访问该文件的进程由 bob:staff 拥有。该系统是MacOS 10.9。该进程可以读取和加载并显示文件就好了;唯一的问题是调用isFile()返回false,这意味着Java认为它不是一个正常的文件。

所以,回到更大的问题,在什么情况下,这个调用会返回false,即使文件存在,路径是否正确,文件是否可访问?

解决方案


该目录也由 _www:staff 拥有,并具有权限 drwxrw -r - 。访问文件的进程由 bob:staff

所有。

该进程在目录上没有x权限(检查)。 JVM用于执行 File.isFile()的系统调用需要此权限。这个系统调用是失败的,所以至少 File.isFile()是不存在的。



在授予r权限的情况下删除目录上的x权限几乎总是一个错误。


I've run into a situation where file.isFile() returns false, which indicates the file is not "normal". However, I can't find a definition of what "normal" means. The docs link to Oracle state:

A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria.

The file is owned by _www:staff and has permissions -rw-r--r--. The directory is also owned by _www:staff and has permissions drwxrw-r--. The process that is accessing the file is owned by bob:staff. The system is MacOS 10.9. The process can read and load and display the file just fine; the only issue is that the call to isFile() returns false, which means Java thinks it is not a normal file.

So, to get back to the larger question, under what conditions will this call return false even though the file does exist, the path is correct, and the file is accessible?

解决方案

The directory is also owned by _www:staff and has permissions drwxrw-r--. The process that is accessing the file is owned by bob:staff.

The process doesn't have "x" permission (examine) on the directory. The system call that the JVM uses to perform File.isFile() requires this permission. This system call is failing, so as far as File.isFile() is concerned the file doesn't exist.

It's almost always a mistake to remove "x" permission on a directory while granting "r" permission.

这篇关于Java:什么构成“正常” File.isFile()的上下文中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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