I wonder what's the difference between using Paths.get() and Path.resolve as in this example:
public static void main(String[] args) {
Path p1 = Paths.get("dir1","dir2","file.jpg");
Path p2 = Paths.get("").resolve("dir1/dir2/file.jpg");
System.out.println(p1.toString()); // yields: dir1/dir2/file.jpg
System.out.println(p2.toString()); // yields: dir1/dir2/file.jpg
}
It looks as if both behave identically, but in a Java EE application I witnessed that p1
got the home directory assigned as a prefix. I found @Aleksandr Dubinsky's answer to this StackOverflow question How to combine paths in Java?, but I don't understand the meaning of the cited javadoc:
Note that Paths.get() (as suggested by someone else) doesn't have an overload taking a Path, and doing Paths.get(path.toString(), childPath) is NOT the same thing as resolve(). From the Paths.get() docs:
Note that while this method is very convenient, using it will imply an assumed reference to the default FileSystem and limit the utility of the calling code. Hence it should not be used in library code intended for flexible reuse. A more flexible alternative is to use an existing Path instance as an anchor, such as:
Path dir = ... Path path = dir.resolve("file");
Specifically, I don't understand what the javadoc wants to say with "will imply an assumed reference to the default FileSystem."