Reputation: 77201
The following tests passes:
File aDir = new File("aDir");
assertTrue(aDir.exists());
assertTrue(aDir.isDirectory());
assertFalse(aDir.isFile());
File aFile = new File("aFile");
assertTrue(aFile.exists());
assertFalse(aFile.isDirectory());
assertTrue(aFile.isFile());
File awol = new File("notInFileSystem");
assertFalse(awol.exists());
assertFalse(awol.isDirectory());
assertFalse(awol.isFile());
On the surface of things, And it seems to imply that for all files where file.isFile()
is true, file.isDirectory()
is false. Is there any known type of file system/file type/java platform where this assumption does not hold?
(There are all sorts of wild in-betweeen categories of files (symlinks, junction points, symlinks/junction points with missing targets etc) that may behave slightly differently)
Upvotes: 2
Views: 2568
Reputation: 5520
Looking at JavaDoc, this seems to be always the case:
http://docs.oracle.com/javase/7/docs/api/java/io/File.html#isFile()
isDirectory:
true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise
isFile:
true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.
Upvotes: 7
Reputation: 33457
From the documentation:
isFile()
:
Tests whether the file denoted by this abstract pathname is a normal file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.
This definitely implies that if isFile()
is true then isDirectory()
must be false. Based on the wording in the isDirectory()
doc, the inverse is true as well.
Upvotes: 1