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 isFile() function is a part of File class in Java. This function determines whether the is a file or Directory denoted by the abstract filename is File or not. The function returns true if the abstract file path is File else returns false. Function signature: public boolean isFile()
list() returns the array of files and directories in the directory defined by this abstract path name. The method returns null, if the abstract pathname does not denote a directory.
Example 1: Java Program to Create a File java is equivalent to // currentdirectory/JavaFile. java File file = new File("JavaFile. java"); We then use the createNewFile() method of the File class to create new file to the specified path.
The File class contains several methods for working with the pathname, deleting and renaming files, creating new directories, listing the contents of a directory, and determining several common attributes of files and directories. It is an abstract representation of files and directory pathnames.
In a Unix system, a file can be a:
"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.
The directory is also owned by
_www:staff
and has permissionsdrwxrw-r--
. The process that is accessing the file is owned bybob: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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With