[英]NIO2 Path Symbols Java
If I created a two paths such as:如果我创建了两条路径,例如:
Path path3 = Paths.get("E:\\data");
Path path4 = Paths.get("E:\\user\\home");
And then make a new Path(relativePath)
by using the relativize()
method on the two paths, creating: "..\user\home"
does the path symbol( ..
) in this case refer to "data" or does it just indicate a relative path?然后通过在两条路径上使用
relativize()
方法创建一个新Path(relativePath)
,创建: "..\user\home"
在这种情况下路径符号( ..
)是指“数据”还是它只是指出一个相对路径?
Path relativePath = path3.relativize(path4);
// ..\user\home <- output
So my Question is, what does the Path symbol ( ..
) represent?所以我的问题是,路径符号(
..
)代表什么?
The relativize
method needs two inputs but doesn't "secretly" encode the base path into it's output, so your relativePath
has to be applied to another base path to actually access a path on disk. relativize
方法需要两个输入,但不会“秘密地”将基本路径编码为 output,因此您的relativePath
必须应用于另一个基本路径才能实际访问磁盘上的路径。
But you can apply it to a different base path, eg if you want to sync two folder structures below two different base paths.但是您可以将其应用于不同的基本路径,例如,如果您想同步两个不同基本路径下的两个文件夹结构。
tl;dr: it just indicates a relative path. tl; dr:它只是表示相对路径。
But take care with your path separator: if you hardcode that into your path strings like in your example, it will fail on other systems.但请注意您的路径分隔符:如果您将其硬编码到您的示例中的路径字符串中,它将在其他系统上失败。 Better split up the individual parts in extra strings like this:
更好地将各个部分拆分为额外的字符串,如下所示:
Path path4 = Paths.get("E:", "user", "home");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.