Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 879
RPW Avatar asked Jul 30 '14 14:07

RPW


People also ask

What is isFile method in Java?

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()

What does the files list () method in Java do?

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.

How do you declare a file in Java?

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.

What is a file write a short note on file class?

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.


2 Answers

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.

like image 114
Dancrumb Avatar answered Sep 22 '22 21:09

Dancrumb


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.

like image 35
Kenster Avatar answered Sep 23 '22 21:09

Kenster