为什么 java.nio.files.Path 中没有 Path 构造函数?
Why there is no Path constructor in java.nio.files.Path?
路径 class 没有记录在案的构造函数,但可以通过它创建实例。 Paths.get( "...." )
是 FileSystems.getDefault().getPath( "..." )
的 shorthand。那么有人可以解释一下这个设计决策吗?
can someone explain this design decision?
这是因为 JSR 203 允许从多个路径发出 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()
。
您使用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()
.
作为 FileSystem
可以用于(几乎)任何事物的证明,这里有一些不同来源的实现:
还有一些其他人。
路径 class 没有记录在案的构造函数,但可以通过它创建实例。 Paths.get( "...." )
是 FileSystems.getDefault().getPath( "..." )
的 shorthand。那么有人可以解释一下这个设计决策吗?
can someone explain this design decision?
这是因为 JSR 203 允许从多个路径发出 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()
。
您使用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()
.
作为 FileSystem
可以用于(几乎)任何事物的证明,这里有一些不同来源的实现:
还有一些其他人。