Most of the file-related operations are not performed in Java; native code exists to perform these activities. In reality, most of the work done depends on the nature of the FileSystem
object (that is backing the File
object) and the underlying implementation of the native IO operations in the OS.
I'll present the case of the implementation in OpenJDK 6, for clarity. The File.exists() implementation defers the actual checks to the FileSystem class:
public boolean exists() {
... calls to SecurityManager have been omitted for brevity ...
return ((fs.getBooleanAttributes(this) & FileSystem.BA_EXISTS) != 0);
}
The FileSystem class is abstract, and an implementation exists for all supported filesystems:
package java.io;
/**
* Package-private abstract class for the local filesystem abstraction.
*/
abstract class FileSystem
Notice the package private nature. A Java Runtime Environment, will provide concrete classes that extend the FileSystem class. In the OpenJDK implementation, there are:
- java.io.WinNTFileSystem, for NTFS
- java.io.Win32FileSystem, for FAT32
- java.io.UnixFileSystem, for *nix filesystems (this is a class with a very broad responsibility).
All of the above classes delegate to native code, for the getBooleanAttributes
method. This implies that performance is not constrained by the managed (Java) code in this case; the implementation of the file system, and the nature of the native calls being made have a greater bearing on performance.
Update #2
Based on the updated question -
I'm not talking about network and tape systems. Lets keep it to ntfs, extX, zfs, jfs
Well, that still doesn't matter. Different operating systems will implement support for different file systems in different ways. For example, NTFS support in Windows will be different from the one in *nix, because the operating system will also have to do it's share of bookkeeping, in addition to communicating with devices via their drivers; not all the work is done in the device.
In Windows, you will almost always find the concept of a file system filter drivers that manages the task of communicating with other file system filter drivers or the file system. This is necessary to support various operations; one example would be the use of filter drivers for anti-virus engines and other software (on-the-fly encryption and compression products) intercepting IO calls.
In *nix, you will have the stat(), system call that will perform the necessary activity of reading the inode information for the file descriptor.