can someone explain this design decision?
It is because JSR 203 allows paths to be issued from more than one FileSystem, unlike File, which is always linked to the file system the JVM lives on. In JSR 203, this filesystem is called the default filesystem. You can get a reference to it using FileSystems.getDefault().
You use Paths.get() to get a path from the default filesystem, which is strictly equivalent to FileSystems.getDefault().getPath(). If you were to get a Path from another file system, you would use this particular file system's .getPath().
As a proof that a FileSystem can be for (nearly) anything, here are a few implementations over different sources:
- in memory;
- FTP;
- SMB/CIFS;
- Dropbox.
And there are a few others.
Answer from fge on Stack OverflowVideos
You can just use the Paths class:
Path path = Paths.get(textPath);
... assuming you want to use the default file system, of course.
From the javadocs..http://docs.oracle.com/javase/tutorial/essential/io/pathOps.html
Path p1 = Paths.get("/tmp/foo");
is the same as
Path p4 = FileSystems.getDefault().getPath("/tmp/foo");
Path p3 = Paths.get(URI.create("file:///Users/joe/FileTest.java"));
Path p5 = Paths.get(System.getProperty("user.home"),"logs", "foo.log");
In Windows, creates file C:\joe\logs\foo.log (assuming user home as C:\joe)
In Unix, creates file /u/joe/logs/foo.log (assuming user home as /u/joe)