1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* Copyright (c) 2024. The RigelA open source project team and
* its contributors reserve all rights.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
use crate::;
//noinspection SpellCheckingInspection
//noinspection GrazieInspection
/**
可用于在文件系统中定位文件的对象。它通常表示与系统相关的文件路径。
Path 表示分层路径,由由特殊分隔符或定界符分隔的目录和文件名元素序列组成。还可能存在标识文件系统层次结构的根组件。
距离目录层次结构的根最远的名称元素是文件或目录的名称。其他名称元素是目录名称。
Path 可以表示根、根和名称序列,或仅表示一个或多个名称元素。
如果 Path 仅由一个空的名称元素组成,则该 Path 被视为空路径。使用空路径访问文件相当于访问文件系统的默认目录。
Path 定义 getFileName、getParent、getRoot 和 subpath 方法来访问路径组件或其名称元素的子序列。
除了访问路径的组件之外,Path 还定义了 resolve 和 resolveSibling 方法来组合路径。 relativize 方法可用于构建两个路径之间的相对路径。
可以使用 startsWith 和 endsWith 方法比较和测试路径。
此接口扩展了 Watchable 接口,以便可以使用 WatchService 注册路径所在的目录并监视目录中的条目。
警告:此接口仅供开发自定义文件系统实现的人员实现。未来版本中可能会向此接口添加方法。
访问文件路径可以与 Files 类一起使用,以操作文件、目录和其他类型的文件。例如,假设我们希望 java.io.BufferedReader 从文件“access.log”中读取文本。
该文件位于相对于当前工作目录的目录“logs”中,并且是 UTF-8 编码的。
Path path = FileSystems.getDefault().getPath("logs", "access.log");
BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
互操作性与默认提供程序关联的路径通常可与 java.io.File 类互操作。其他提供程序创建的路径不太可能与 java.io.File 表示的抽象路径名互操作。
toPath 方法可用于从 java.io.File 对象表示的抽象路径名获取 Path。生成的 Path 可用于对与 java.io.File 对象相同的文件进行操作。
此外,toFile 方法可用于从 Path 的字符串表示构造 File。并发性此接口的实现是不可变的,并且可以安全地供多个并发线程使用。
*/