为什么java.nio.files.Path中没有Path构造函数? [英] Why there is no Path constructor in java.nio.files.Path?

查看:125
本文介绍了为什么java.nio.files.Path中没有Path构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Path类没有记录的构造函数,但是可以通过创建实例。 Paths.get(....)这是 FileSystems.getDefault()的简写.getPath(...)。那么有人可以解释这个设计决定吗?

The Path class has no documented constructor, but one creates instances via. Paths.get( "...." ) which is a shorthand for FileSystems.getDefault().getPath( "..." ). So can someone explain this design decission?

推荐答案


有人可以解释这个设计决定吗?

can someone explain this design decision?

这是因为JSR 203允许从多个 FileSystem ,与文件不同,它始终链接到JVM所在的文件系统。在JSR 203中,此文件系统称为默认文件系统。您可以使用 FileSystems.getDefault()

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().

您使用 Paths.get() 从默认文件系统获取路径,该路径严格等同于 FileSystems.getDefault()。getPath()。如果您要从另一个文件系统获得 Path ,您将使用此特定文件系统的 .getPath()

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.

还有其他一些。

这篇关于为什么java.nio.files.Path中没有Path构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆