The javadoc for .isAbsolute()
says:
Tells whether or not this path is absolute.
An absolute path is complete in that it doesn't need to be combined with other path information in order to locate a file.Returns:
true
if, and only if, this path is absolute
The javadoc for .getRoot()
says:
Returns the root component of this path as a Path object, or null if this path does not have a root component.
Returns: a path representing the root component of this path, or
null
OK, so, I am at a loss here; are there any filesystems out there for which a path may be absolute without a root at all?
EDIT: note that there CAN be paths which have a root but are NOT absolute. For instance, these on Windows systems:
C:foo
;\foo\bar
.But I am asking for the reverse here: no root and absolute.
In Java, Path, and File both are classes. They belong to different packages but perform the same mechanism. We can say that the Java Path class is the advanced version of the File class. We use both the classes for the File I/O operations.
io. File. getAbsolutePath() is used to obtain the absolute path of a file in the form of a string. This method requires no parameters.
A path can point to either a file or a directory. A path can be absolute or relative. An absolute path contains the full path from the root of the file system down to the file or directory it points to. A relative path contains the path to the file or directory relative to some other path.
A Path object contains the file name and directory list used to construct the path and is used to examine, locate, and manipulate files. The helper class, java. nio. file. Paths (in plural form) is the formal way of creating Path objects.
Well, there are some obscure things with file systems. I made a few enterprise search crawlers, and somewhere down the road you will notice some strange file system things going on with paths. BTW: these are all implementations of custom (overridden) file systems, so no standard ones, and you can definitely argue for hours on what of those things are good ideas and what are not... Still, I don't think you'll encounter any of these cases with the standard file systems.
Here goes a few examples of strange things:
Files in container file systems (OLE2, ZIP, TAR, etc): c:\foo\bar\blah.zip\myfile
In this case, you can decide what item is 'the root':
'graph' like structures like HTTP:
Still, you can argue that the top-most common path (if that exists...) that you can reach is the root or that there is a root - but you simply cannot reach it (even though it's really non-existent).
Samba/netbios
If you see a complete Samba (windows networking) network as a single file system, then you basically end up with a 'root' containing all workgroups, a workgroup containing all computers, a computer containing all shares, and then the files in the share.
However... the root and the workgroups don't really exist. They are things that are made up from a broadcast protocol (which is also quite unreliable if you have a network of over 1000 computers). From a crawler perspective, it makes all the sense in the world to treat the 'root' and 'workgroup' directories completely different from the (reliable) rest.
However
These scenario's describe only paths where the root is unreachable, unreliable or something else. Theoretically, I suppose that in any URL you can think of, there is always a root. After all, it's made up as a string of characters defining a hierarchy, which therefore by definition has a start.
From my understanding of the subject, an absolute path can only be absolute if it can be traced back to it's root. As such there should never be an absolute path without a root. Ultimately this just comes down to semantics and although we can find definitions that define the absolute path such (egs below);
The only real question left after this point is whether the definition by the Java API follows suit. The only place I can find reference to the definition of an absolute path (with reference to the root element) from an official Oracle source is from inside the official Java tutorial. The official Java tutorials say
An absolute path always contains the root element
If this statement is to be believed, then no file system (no matter how obscure) can contain a Path that the Java API will consider absolute, unless it also considers it to contain a root.
You could argue that in some non-heirarchical file systems you might fall into some issues deciding whether a file can be it's own root. However, by this definition in the Path API (emphasis mine), a path should not represent a non-hierarchical element;
A Path represents a path that is hierarchical and composed of a sequence of directory and file name elements
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