Java: What constitutes a “normal” file in the context of File.isFile()?

那年仲夏 提交于 2019-12-07 04:41:06

问题


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?


回答1:


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.




回答2:


In a Unix system, a file can be a:

  • Regular file
  • Directory
  • Symbolic Link
  • Named pipe
  • Socket
  • Device file
  • Door (Sun Solaris system)

"Normal" file refers to a regular file here. It's the one type of file where the system does not impose any requirement on the file's internal structure.



来源:https://stackoverflow.com/questions/25039156/java-what-constitutes-a-normal-file-in-the-context-of-file-isfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!