js-apis-fileio.md 127.1 KB
Newer Older
Z
zhangxingxia 已提交
1
文件管理
Z
zengyawen 已提交
2

Z
zengyawen 已提交
3 4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Z
zengyawen 已提交
5

W
wangbo 已提交
6
该模块提供文件存储管理能力,包括文件基本管理、文件目录管理、文件信息统计、文件流式读写等常用功能。
Z
zhangxingxia 已提交
7

Z
zengyawen 已提交
8
## 导入模块
Z
zengyawen 已提交
9

Z
zhangxingxia 已提交
10
```js
Z
zengyawen 已提交
11 12 13
import fileio from '@ohos.fileio';
```

Z
zengyawen 已提交
14 15

## 使用说明
Z
zengyawen 已提交
16

W
wangbo 已提交
17 18 19 20
使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考:
 ```js
 import featureAbility from '@ohos.ability.featureAbility';
 let context = featureAbility.getContext();
W
wangbo 已提交
21 22 23 24
 let path = '';
 context.getFilesDir().then((data) => {
      path = data;
 })
Z
zhangxingxia 已提交
25
 ```
Z
zengyawen 已提交
26 27


Z
zengyawen 已提交
28 29 30 31
## fileio.stat

stat(path: string): Promise<Stat>

H
haonan_7 已提交
32
获取文件信息,使用Promise异步回调。
Z
zengyawen 已提交
33

34 35
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
36
**参数:**
Z
zhangxingxia 已提交
37

Z
zengyawen 已提交
38 39 40
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待获取文件的应用沙箱路径。 |
Z
zhangxingxia 已提交
41

Z
zhangxingxia 已提交
42
**返回值:**
Z
zhangxingxia 已提交
43

H
HelloCrease 已提交
44 45
  | 类型                           | 说明         |
  | ---------------------------- | ---------- |
H
haonan_7 已提交
46
  | Promise<[Stat](#stat)> | Promise对象。返回文件的具体信息。 |
Z
zhangxingxia 已提交
47

Z
zhangxingxia 已提交
48
**示例:**
Z
zhangxingxia 已提交
49 50
  ```js
  fileio.stat(path).then(function(stat){
H
haonan_7 已提交
51
      console.info("getFileInfo succeed:"+ JSON.stringify(stat));
Z
zhangxingxia 已提交
52 53 54
  }).catch(function(err){
      console.info("getFileInfo failed with error:"+ err);
  });
Z
zengyawen 已提交
55 56 57 58 59 60 61
  ```


## fileio.stat

stat(path:string, callback:AsyncCallback<Stat>): void

H
haonan_7 已提交
62
获取文件信息,使用callback异步回调。
Z
zengyawen 已提交
63

64 65
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
66
**参数:**
Z
zengyawen 已提交
67 68 69 70
| 参数名   | 类型                               | 必填 | 说明                           |
| -------- | ---------------------------------- | ---- | ------------------------------ |
| path     | string                             | 是   | 待获取文件的应用沙箱路径。     |
| callback | AsyncCallback<[Stat](#stat)> | 是   | 异步获取文件的信息之后的回调。 |
Z
zengyawen 已提交
71

Z
zhangxingxia 已提交
72
**示例:**
Z
zhangxingxia 已提交
73
  ```js
Z
zengyawen 已提交
74
  fileio.stat(path, function (err, stat) {
Z
zhangxingxia 已提交
75
      // example code in Stat
Z
zengyawen 已提交
76 77 78 79
  });
  ```


Z
zengyawen 已提交
80 81 82
## fileio.statSync

statSync(path:string): Stat
Z
zengyawen 已提交
83 84 85

以同步方法获取文件的信息。

86 87
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
88
**参数:**
Z
zengyawen 已提交
89 90 91
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待获取文件的应用沙箱路径。 |
Z
zengyawen 已提交
92 93


Z
zhangxingxia 已提交
94
**返回值:**
H
HelloCrease 已提交
95 96
  | 类型            | 说明         |
  | ------------- | ---------- |
Z
zengyawen 已提交
97 98
  | [Stat](#stat) | 表示文件的具体信息。 |

Z
zhangxingxia 已提交
99
**示例:**
Z
zhangxingxia 已提交
100
  ```js
Z
zengyawen 已提交
101
  let stat = fileio.statSync(path);
Z
zengyawen 已提交
102
  // example code in Stat
Z
zengyawen 已提交
103 104 105
  ```


Z
zengyawen 已提交
106
## fileio.opendir
Z
zengyawen 已提交
107

Z
zengyawen 已提交
108
opendir(path: string): Promise<Dir>
Z
zengyawen 已提交
109

H
haonan_7 已提交
110
打开文件目录,使用Promise异步回调。
Z
zengyawen 已提交
111

112 113
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
114
**参数:**
Z
zengyawen 已提交
115 116 117
| 参数名 | 类型   | 必填 | 说明                           |
| ------ | ------ | ---- | ------------------------------ |
| path   | string | 是   | 待打开文件目录的应用沙箱路径。 |
Z
zengyawen 已提交
118

Z
zhangxingxia 已提交
119
**返回值:**
H
HelloCrease 已提交
120 121
  | 类型                         | 说明       |
  | -------------------------- | -------- |
H
haonan_7 已提交
122
  | Promise<[Dir](#dir)> | Promise对象。返回Dir对象。 |
Z
zengyawen 已提交
123

Z
zhangxingxia 已提交
124
**示例:**
Z
zhangxingxia 已提交
125 126
  ```js
  fileio.opendir(path).then(function(dir){
H
haonan_7 已提交
127
      console.info("opendir succeed:"+ JSON.stringify(dir));
Z
zhangxingxia 已提交
128 129 130
  }).catch(function(err){
      console.info("opendir failed with error:"+ err);
  });
Z
zengyawen 已提交
131 132 133
  ```


Z
zengyawen 已提交
134
## fileio.opendir
Z
zengyawen 已提交
135

Z
zengyawen 已提交
136
opendir(path: string, callback: AsyncCallback<Dir>): void
Z
zengyawen 已提交
137

H
haonan_7 已提交
138
打开文件目录,使用callback异步回调。
Z
zengyawen 已提交
139

140 141
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
142
**参数:**
Z
zhangxingxia 已提交
143

Z
zengyawen 已提交
144 145 146 147
| 参数名   | 类型                             | 必填 | 说明                           |
| -------- | -------------------------------- | ---- | ------------------------------ |
| path     | string                           | 是   | 待打开文件目录的应用沙箱路径。 |
| callback | AsyncCallback<[Dir](#dir)> | 是   | 异步打开文件目录之后的回调。   |
Z
zhangxingxia 已提交
148

Z
zhangxingxia 已提交
149
**示例:**
Z
zhangxingxia 已提交
150
  ```js
Z
zengyawen 已提交
151
  fileio.opendir(path, function (err, dir) { 
Z
zhangxingxia 已提交
152 153
      // example code in Dir struct
      // use read/readSync/close
Z
zengyawen 已提交
154
  });
Z
zengyawen 已提交
155 156 157
  ```


Z
zengyawen 已提交
158
## fileio.opendirSync
Z
zengyawen 已提交
159

Z
zengyawen 已提交
160 161 162
opendirSync(path: string): Dir

以同步方法打开文件目录。
Z
zengyawen 已提交
163

164 165
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zengyawen 已提交
166

Z
zhangxingxia 已提交
167
**参数:**
Z
zhangxingxia 已提交
168

Z
zengyawen 已提交
169 170 171
| 参数名 | 类型   | 必填 | 说明                           |
| ------ | ------ | ---- | ------------------------------ |
| path   | string | 是   | 待打开文件目录的应用沙箱路径。 |
Z
zhangxingxia 已提交
172

Z
zhangxingxia 已提交
173
**返回值:**
H
HelloCrease 已提交
174 175
  | 类型          | 说明       |
  | ----------- | -------- |
Z
zengyawen 已提交
176
  | [Dir](#dir) | 返回Dir对象。 |
Z
zengyawen 已提交
177

Z
zhangxingxia 已提交
178
**示例:**
Z
zhangxingxia 已提交
179
  ```js
Z
zengyawen 已提交
180 181 182
  let dir = fileio.opendirSync(path);
  // example code in Dir struct
  // use read/readSync/close
Z
zengyawen 已提交
183 184 185
  ```


Z
zengyawen 已提交
186
## fileio.access
Z
zengyawen 已提交
187

Z
zengyawen 已提交
188
access(path: string, mode?: number): Promise<void>
Z
zengyawen 已提交
189

H
haonan_7 已提交
190
检查当前进程是否可访问某文件,使用Promise异步回调。
Z
zengyawen 已提交
191

192 193
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
194
**参数:**
Z
zhangxingxia 已提交
195

Z
zengyawen 已提交
196 197 198 199
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path   | string | 是   | 待访问文件的应用沙箱路径。                                   |
| mode   | number | 否   | 访问文件时的选项,可给定如下选项,以按位或的方式使用多个选项,默认给定0。<br/>确认当前进程是否具有对应权限:<br/>-&nbsp;0:确认文件是否存在。<br/>-&nbsp;1:确认当前进程是否具有可执行权限。<br/>-&nbsp;2:确认当前进程是否具有写权限。<br/>-&nbsp;4:确认当前进程是否具有读权限。 |
Z
zhangxingxia 已提交
200

Z
zhangxingxia 已提交
201
**返回值:**
H
HelloCrease 已提交
202 203
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
204
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
205

Z
zhangxingxia 已提交
206
**示例:**
Z
zhangxingxia 已提交
207 208
  ```js
  fileio.access(path).then(function() {
H
haonan_7 已提交
209
      console.info("access succeed");
Z
zhangxingxia 已提交
210 211
  }).catch(function(err){
      console.info("access failed with error:"+ err);
Z
zengyawen 已提交
212
  });
Z
zengyawen 已提交
213 214 215
  ```


Z
zengyawen 已提交
216
## fileio.access
Z
zengyawen 已提交
217

218
access(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
Z
zengyawen 已提交
219

H
haonan_7 已提交
220
检查当前进程是否可访问某文件,使用callback异步回调。
Z
zengyawen 已提交
221

222 223
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
224
**参数:**
Z
zengyawen 已提交
225 226 227 228 229
| 参数名   | 类型                      | 必填 | 说明                                                         |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path     | string                    | 是   | 待访问文件的应用沙箱路径。                                   |
| mode     | number                    | 否   | 访问文件时的选项,可给定如下选项,以按位或的方式使用多个选项,默认给定0。<br/>确认当前进程是否具有对应权限:<br/>-&nbsp;0:确认文件是否存在。<br/>-&nbsp;1:确认当前进程是否具有可执行权限。<br/>-&nbsp;2:确认当前进程是否具有写权限。<br/>-&nbsp;4:确认当前进程是否具有读权限。 |
| callback | AsyncCallback&lt;void&gt; | 是   | 异步检查当前进程是否可访问某文件之后的回调。                 |
Z
zengyawen 已提交
230

Z
zhangxingxia 已提交
231
**示例:**
Z
zhangxingxia 已提交
232
  ```js
Z
zengyawen 已提交
233
  fileio.access(path, function (err) {
Z
zhangxingxia 已提交
234
      // do something
Z
zengyawen 已提交
235
  });
Z
zengyawen 已提交
236 237 238
  ```


Z
zengyawen 已提交
239
## fileio.accessSync
Z
zengyawen 已提交
240

Z
zengyawen 已提交
241 242 243
accessSync(path: string, mode?: number): void

以同步方法检查当前进程是否可访问某文件。
Z
zengyawen 已提交
244

245
**系统能力**:SystemCapability.FileManagement.File.FileIO
Z
zengyawen 已提交
246

Z
zhangxingxia 已提交
247
**参数:**
Z
zengyawen 已提交
248 249 250 251
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path   | string | 是   | 待访问文件的应用沙箱路径。                                   |
| mode   | number | 否   | 访问文件时的选项,可给定如下选项,以按位或的方式使用多个选项,默认给定0。<br/>确认当前进程是否具有对应权限:<br/>-&nbsp;0:确认文件是否存在。<br/>-&nbsp;1:确认当前进程是否具有可执行权限。<br/>-&nbsp;2:确认当前进程是否具有写权限。<br/>-&nbsp;4:确认当前进程是否具有读权限。 |
Z
zengyawen 已提交
252

Z
zhangxingxia 已提交
253
**示例:**
Z
zhangxingxia 已提交
254
  ```js
Z
zengyawen 已提交
255 256
  try {
      fileio.accessSync(path);
Z
zhangxingxia 已提交
257 258
  } catch(err) {
      console.info("accessSync failed with error:"+ err);
Z
zengyawen 已提交
259
  }
Z
zengyawen 已提交
260 261 262
  ```


Z
zengyawen 已提交
263
## fileio.close<sup>7+</sup>
Z
zengyawen 已提交
264

Z
zengyawen 已提交
265
close(fd: number):Promise&lt;void&gt;
Z
zengyawen 已提交
266

H
haonan_7 已提交
267
关闭文件,使用Promise异步回调。
Z
zengyawen 已提交
268

269 270
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
271
**参数:**
H
HelloCrease 已提交
272 273 274
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
  | fd   | number | 是    | 待关闭文件的文件描述符。 |
Z
zengyawen 已提交
275

Z
zhangxingxia 已提交
276
**返回值:**
H
HelloCrease 已提交
277 278
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
279
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
280

Z
zhangxingxia 已提交
281
**示例:**
Z
zhangxingxia 已提交
282
  ```js
Z
zengyawen 已提交
283
  let fd = fileio.openSync(path);
Z
zhangxingxia 已提交
284
  fileio.close(fd).then(function(){
H
haonan_7 已提交
285
      console.info("close file succeed");
Z
zhangxingxia 已提交
286 287 288
  }).catch(function(err){
      console.info("close file failed with error:"+ err);
  });
Z
zengyawen 已提交
289 290 291
  ```


Z
zengyawen 已提交
292
## fileio.close<sup>7+</sup>
Z
zengyawen 已提交
293

Z
zengyawen 已提交
294
close(fd: number, callback:AsyncCallback&lt;void&gt;): void
Z
zengyawen 已提交
295

H
haonan_7 已提交
296
关闭文件,使用callback异步回调。
Z
zengyawen 已提交
297

298 299
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
300
**参数:**
H
HelloCrease 已提交
301 302 303 304
  | 参数名      | 类型                        | 必填   | 说明           |
  | -------- | ------------------------- | ---- | ------------ |
  | fd       | number                    | 是    | 待关闭文件的文件描述符。 |
  | callback | AsyncCallback&lt;void&gt; | 是    | 异步关闭文件之后的回调。 |
Z
zengyawen 已提交
305

Z
zhangxingxia 已提交
306
**示例:**
Z
zhangxingxia 已提交
307
  ```js
Z
zengyawen 已提交
308
  let fd = fileio.openSync(path);
Z
zhangxingxia 已提交
309 310
  fileio.close(fd, function (err) {
      // do something
Z
zengyawen 已提交
311
  });
Z
zengyawen 已提交
312 313 314
  ```


Z
zengyawen 已提交
315
## fileio.closeSync
Z
zengyawen 已提交
316

Z
zengyawen 已提交
317
closeSync(fd: number): void
Z
zengyawen 已提交
318

Z
zengyawen 已提交
319
以同步方法关闭文件。
Z
zengyawen 已提交
320

321 322
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
323
**参数:**
H
HelloCrease 已提交
324 325 326
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
  | fd   | number | 是    | 待关闭文件的文件描述符。 |
Z
zengyawen 已提交
327

Z
zhangxingxia 已提交
328
**示例:**
Z
zhangxingxia 已提交
329
  ```js
Z
zengyawen 已提交
330
  fileio.closeSync(fd);
Z
zengyawen 已提交
331 332 333
  ```


W
wangbo 已提交
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
## fileio.close<sup>7+</sup>

close(): Promise&lt;void&gt;

关闭文件流,使用Promise异步回调。

**系统能力**:SystemCapability.FileManagement.File.FileIO

**返回值:**
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
  | Promise&lt;void&gt; | Promise对象。无返回值。 |

**示例:**
  ```js
  fileio.close().then(function(){
      console.info("close file stream succeed");
  }).catch(function(err){
      console.info("close file stream failed with error:"+ err);
  });
  ```


## fileio.close<sup>7+</sup>

close(callback: AsyncCallback&lt;void&gt;): void

关闭文件流,使用callback异步回调。

**系统能力**:SystemCapability.FileManagement.File.FileIO

**参数:**
  | 参数名      | 类型                        | 必填   | 说明            |
  | -------- | ------------------------- | ---- | ------------- |
  | callback | AsyncCallback&lt;void&gt; | 是    | 异步关闭文件流之后的回调。 |

**示例:**
  ```js
  fileio.close(function(err){
      // do something
  });
  ```
Z
zengyawen 已提交
376 377


Z
zengyawen 已提交
378
## fileio.copyFile
Z
zengyawen 已提交
379

Z
zengyawen 已提交
380
copyFile(src:string | number, dest:string | number, mode?:number):Promise&lt;void&gt;
Z
zengyawen 已提交
381

H
haonan_7 已提交
382
复制文件,使用Promise异步回调。
Z
zengyawen 已提交
383

384 385
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
386
**参数:**
H
HelloCrease 已提交
387 388 389 390 391
  | 参数名  | 类型                         | 必填   | 说明                                       |
  | ---- | -------------------------- | ---- | ---------------------------------------- |
  | src  | string&nbsp;\|&nbsp;number | 是    | 待复制文件的路径或待复制文件的描述符。                      |
  | dest | string&nbsp;\|&nbsp;number | 是    | 目标文件路径或目标文件描述符。                          |
  | mode | number                     | 否    | mode提供覆盖文件的选项,当前仅支持0,且默认为0。<br/>0:完全覆盖目标文件,未覆盖部分将被裁切掉。 |
Z
zengyawen 已提交
392

Z
zhangxingxia 已提交
393
**返回值:**
H
HelloCrease 已提交
394 395
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
396
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
397

Z
zhangxingxia 已提交
398
**示例:**
Z
zhangxingxia 已提交
399
  ```js
W
wangbo 已提交
400
  fileio.copyFile(src, dest).then(function(){
H
haonan_7 已提交
401
      console.info("copyFile succeed");
Z
zhangxingxia 已提交
402 403 404
  }).catch(function(err){
      console.info("copyFile failed with error:"+ err);
  });
Z
zengyawen 已提交
405 406 407
  ```


Z
zengyawen 已提交
408
## fileio.copyFile
Z
zengyawen 已提交
409

410
copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback&lt;void&gt;): void
Z
zengyawen 已提交
411

H
haonan_7 已提交
412
复制文件,使用callback异步回调。
Z
zengyawen 已提交
413

414 415
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
416
**参数:**
H
HelloCrease 已提交
417 418 419 420 421 422
  | 参数名      | 类型                         | 必填   | 说明                                       |
  | -------- | -------------------------- | ---- | ---------------------------------------- |
  | src      | string&nbsp;\|&nbsp;number | 是    | 待复制文件的路径或待复制文件的描述符。                      |
  | dest     | string&nbsp;\|&nbsp;number | 是    | 目标文件路径或目标文件描述符。                          |
  | mode     | number                     | 否    | mode提供覆盖文件的选项,当前仅支持0,且默认为0。<br/>0:完全覆盖目标文件,未覆盖部分将被裁切掉。 |
  | callback | AsyncCallback&lt;void&gt;  | 是    | 异步复制文件之后的回调。                             |
Z
zengyawen 已提交
423

Z
zhangxingxia 已提交
424
**示例:**
Z
zhangxingxia 已提交
425
  ```js
W
wangbo 已提交
426
  fileio.copyFile(src, dest, function (err) {
Z
zhangxingxia 已提交
427
      // do something
Z
zengyawen 已提交
428
  });
Z
zengyawen 已提交
429 430 431
  ```


Z
zengyawen 已提交
432
## fileio.copyFileSync
Z
zengyawen 已提交
433

434
copyFileSync(src: string | number, dest: string | number, mode?: number): void
Z
zengyawen 已提交
435

Z
zengyawen 已提交
436
以同步方法复制文件。
Z
zengyawen 已提交
437

438 439
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
440
**参数:**
H
HelloCrease 已提交
441 442 443 444 445
  | 参数名  | 类型                         | 必填   | 说明                                       |
  | ---- | -------------------------- | ---- | ---------------------------------------- |
  | src  | string&nbsp;\|&nbsp;number | 是    | 待复制文件的路径或待复制文件的描述符。                      |
  | dest | string&nbsp;\|&nbsp;number | 是    | 目标文件路径或目标文件描述符。                          |
  | mode | number                     | 否    | mode提供覆盖文件的选项,当前仅支持0,且默认为0。<br/>0:完全覆盖目标文件,未覆盖部分将被裁切掉。 |
Z
zengyawen 已提交
446

Z
zhangxingxia 已提交
447
**示例:**
Z
zhangxingxia 已提交
448
  ```js
W
wangbo 已提交
449
  fileio.copyFileSync(src, dest);
Z
zengyawen 已提交
450 451 452
  ```


Z
zengyawen 已提交
453
## fileio.mkdir
Z
zengyawen 已提交
454

Z
zengyawen 已提交
455 456
mkdir(path:string, mode?: number): Promise&lt;void&gt;

H
haonan_7 已提交
457
创建目录,使用Promise异步回调。
Z
zengyawen 已提交
458

459
**系统能力**:SystemCapability.FileManagement.File.FileIO
Z
zengyawen 已提交
460

Z
zhangxingxia 已提交
461
**参数:**
Z
zengyawen 已提交
462 463 464 465
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path   | string | 是   | 待创建目录的应用沙箱路径。                                   |
| mode   | number | 否   | 创建目录的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o775。<br/>-&nbsp;0o775:所有者具有读、写及可执行权限,其余用户具有读及可执行权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
Z
zengyawen 已提交
466

Z
zhangxingxia 已提交
467
**返回值:**
H
HelloCrease 已提交
468 469
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
470
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
471

Z
zhangxingxia 已提交
472
**示例:**
Z
zhangxingxia 已提交
473 474
  ```js
  fileio.mkdir(path).then(function() {
H
haonan_7 已提交
475
      console.info("mkdir succeed");
Z
zhangxingxia 已提交
476 477 478
  }).catch(function (error){
      console.info("mkdir failed with error:"+ error);
  });
Z
zengyawen 已提交
479 480 481
  ```


Z
zengyawen 已提交
482
## fileio.mkdir
Z
zengyawen 已提交
483

484
mkdir(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
Z
zengyawen 已提交
485

H
haonan_7 已提交
486
创建目录,使用callback异步回调。
Z
zengyawen 已提交
487

488 489
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
490
**参数:**
Z
zengyawen 已提交
491 492 493 494 495
| 参数名   | 类型                      | 必填 | 说明                                                         |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path     | string                    | 是   | 待创建目录的应用沙箱路径。                                   |
| mode     | number                    | 否   | 创建目录的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o775。<br/>-&nbsp;0o775:所有者具有读、写及可执行权限,其余用户具有读及可执行权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
| callback | AsyncCallback&lt;void&gt; | 是   | 异步创建目录操作完成之后的回调。                             |
Z
zengyawen 已提交
496

Z
zhangxingxia 已提交
497
**示例:**
Z
zhangxingxia 已提交
498 499
  ```js
  fileio.mkdir(path, function(err) {
H
haonan_7 已提交
500
    console.info("mkdir succeed");
Z
zengyawen 已提交
501
  });
Z
zengyawen 已提交
502 503 504
  ```


Z
zengyawen 已提交
505
## fileio.mkdirSync
Z
zengyawen 已提交
506

507
mkdirSync(path: string, mode?: number): void
Z
zengyawen 已提交
508

Z
zengyawen 已提交
509
以同步方法创建目录。
Z
zengyawen 已提交
510

511 512
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
513
**参数:**
Z
zengyawen 已提交
514 515 516 517
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path   | string | 是   | 待创建目录的应用沙箱路径。                                   |
| mode   | number | 否   | 创建目录的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o775。<br/>-&nbsp;0o775:所有者具有读、写及可执行权限,其余用户具有读及可执行权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
Z
zengyawen 已提交
518

Z
zhangxingxia 已提交
519
**示例:**
Z
zhangxingxia 已提交
520
  ```js
Z
zengyawen 已提交
521 522 523 524 525 526 527 528
  fileio.mkdirSync(path);
  ```


## fileio.open<sup>7+</sup>

open(path: string, flags?: number, mode?: number): Promise&lt;number&gt;

H
haonan_7 已提交
529
打开文件,使用Promise异步回调。
Z
zengyawen 已提交
530

531 532
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
533
**参数:**
Z
zengyawen 已提交
534 535 536
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path   | string | 是   | 待打开文件的应用沙箱路径。                                   |
R
raoxian 已提交
537
| flags  | number | 否   | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:<br/>-&nbsp;0o0:只读打开。<br/>-&nbsp;0o1:只写打开。<br/>-&nbsp;0o2:读写打开。<br/>同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:<br/>-&nbsp;0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数&nbsp;mode。<br/>-&nbsp;0o200:如果追加了0o100选项,且文件已经存在,则出错。<br/>-&nbsp;0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。<br/>-&nbsp;0o2000:以追加方式打开,后续写将追加到文件末尾。<br/>-&nbsp;0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续&nbsp;IO&nbsp;进行非阻塞操作。<br/>-&nbsp;0o200000:如果path不指向目录,则出错。<br/>-&nbsp;0o400000:如果path指向符号链接,则出错。<br/>-&nbsp;0o4010000:以同步IO的方式打开文件。 |
Z
zengyawen 已提交
538
| mode   | number | 否   | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。<br/>-&nbsp;0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
Z
zengyawen 已提交
539

Z
zhangxingxia 已提交
540
**返回值:**
H
HelloCrease 已提交
541 542
  | 类型                    | 说明          |
  | --------------------- | ----------- |
H
haonan_7 已提交
543
  | Promise&lt;number&gt; | Promise对象。返回打开文件的文件描述符。 |
Z
zengyawen 已提交
544

Z
zhangxingxia 已提交
545
**示例:**
Z
zhangxingxia 已提交
546 547
  ```js
  fileio.open(path, 0o1, 0o0200).then(function(number){
H
haonan_7 已提交
548
      console.info("open file succeed");
Z
zhangxingxia 已提交
549
  }).catch(function(err){
Z
zhangxingxia 已提交
550 551
      console.info("open file failed with error:"+ err);
  });
Z
zengyawen 已提交
552 553 554
  ```


Z
zengyawen 已提交
555
## fileio.open<sup>7+</sup>
Z
zengyawen 已提交
556

Z
zengyawen 已提交
557
open(path: string, flags: number, mode: number, callback: AsyncCallback&lt;number&gt;): void
Z
zengyawen 已提交
558

H
haonan_7 已提交
559
打开文件,使用callback异步回调。
Z
zengyawen 已提交
560

561 562
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
563
**参数:**
Z
zengyawen 已提交
564 565 566
| 参数名   | 类型                            | 必填 | 说明                                                         |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| path     | string                          | 是   | 待打开文件的应用沙箱路径。                                   |
R
raoxian 已提交
567
| flags    | number                          | 是   | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:<br/>-&nbsp;0o0:只读打开。<br/>-&nbsp;0o1:只写打开。<br/>-&nbsp;0o2:读写打开。<br/>同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:<br/>-&nbsp;0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数&nbsp;mode。<br/>-&nbsp;0o200:如果追加了0o100选项,且文件已经存在,则出错。<br/>-&nbsp;0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。<br/>-&nbsp;0o2000:以追加方式打开,后续写将追加到文件末尾。<br/>-&nbsp;0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续&nbsp;IO&nbsp;进行非阻塞操作。<br/>-&nbsp;0o200000:如果path不指向目录,则出错。<br/>-&nbsp;0o400000:如果path指向符号链接,则出错。<br/>-&nbsp;0o4010000:以同步IO的方式打开文件。 |
Z
zengyawen 已提交
568 569
| mode     | number                          | 是   | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。<br/>-&nbsp;0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
| callback | AsyncCallback&nbsp;&lt;void&gt; | 是   | 异步打开文件之后的回调。                                     |
Z
zengyawen 已提交
570

Z
zhangxingxia 已提交
571
**示例:**
Z
zhangxingxia 已提交
572 573 574
  ```js
  fileio.open(path, 0, function(err, fd) {
      // do something
Z
zengyawen 已提交
575
  });
Z
zengyawen 已提交
576 577 578
  ```


Z
zengyawen 已提交
579
## fileio.openSync
Z
zengyawen 已提交
580

Z
zengyawen 已提交
581
openSync(path:string, flags?:number, mode?:number): number
Z
zengyawen 已提交
582

Z
zengyawen 已提交
583
以同步方法打开文件。
Z
zengyawen 已提交
584

585 586
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
587
**参数:**
Z
zengyawen 已提交
588 589 590
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path   | string | 是   | 待打开文件的应用沙箱路径。                                   |
R
raoxian 已提交
591
| flags  | number | 否   | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:<br/>-&nbsp;0o0:只读打开。<br/>-&nbsp;0o1:只写打开。<br/>-&nbsp;0o2:读写打开。<br/>同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:<br/>-&nbsp;0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数&nbsp;mode。<br/>-&nbsp;0o200:如果追加了0o100选项,且文件已经存在,则出错。<br/>-&nbsp;0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。<br/>-&nbsp;0o2000:以追加方式打开,后续写将追加到文件末尾。<br/>-&nbsp;0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续&nbsp;IO&nbsp;进行非阻塞操作。<br/>-&nbsp;0o200000:如果path不指向目录,则出错。<br/>-&nbsp;0o400000:如果path指向符号链接,则出错。<br/>-&nbsp;0o4010000:以同步IO的方式打开文件。 |
W
wangbo 已提交
592
| mode   | number | 否   | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。<br/>-&nbsp;0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。<br/>-&nbsp;0o640:所有者具有读、写权限,所有用户组具有读权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。<br/>创建出的文件权限受umask影响,umask随进程启动确定,其修改当前不开放。 |
Z
zengyawen 已提交
593

Z
zhangxingxia 已提交
594
**返回值:**
H
HelloCrease 已提交
595 596
  | 类型     | 说明          |
  | ------ | ----------- |
Z
zengyawen 已提交
597
  | number | 打开文件的文件描述符。 |
Z
zengyawen 已提交
598

Z
zhangxingxia 已提交
599
**示例:**
Z
zhangxingxia 已提交
600
  ```js
W
wangbo 已提交
601 602 603 604 605 606 607 608 609
  let fd = fileio.openSync(path, 0o102, 0o640);
  ```
  ```js
  let fd = fileio.openSync(path, 0o102, 0o666);
  fileio.writeSync(fd, 'hello world');
  let fd1 = fileio.openSync(path, 0o2002);
  fileio.writeSync(fd1, 'hello world');
  let num = fileio.readSync(fd1, new ArrayBuffer(4096), {position: 0});
  console.info("num == " + num);
R
raoxian 已提交
610
  ```
Z
zengyawen 已提交
611 612


Z
zengyawen 已提交
613
## fileio.read
Z
zengyawen 已提交
614

615 616 617 618 619
read(fd: number, buffer: ArrayBuffer, options?: {
    offset?: number;
    length?: number;
    position?: number;
}): Promise&lt;ReadOut&gt;
Z
zengyawen 已提交
620

H
haonan_7 已提交
621
从文件读取数据,使用Promise异步回调。
Z
zengyawen 已提交
622

623 624
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
625
**参数:**
Z
zhangxingxia 已提交
626 627 628 629
| 参数名  | 类型        | 必填 | 说明                                                         |
| ------- | ----------- | ---- | ------------------------------------------------------------ |
| fd      | number      | 是   | 待读取文件的文件描述符。                                     |
| buffer  | ArrayBuffer | 是   | 用于保存读取到的文件数据的缓冲区。                           |
Z
zhangxingxia 已提交
630
| options | Object      | 否   | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>约束:offset+length<=buffer.size。 |
Z
zengyawen 已提交
631

Z
zhangxingxia 已提交
632
**返回值:**
Z
zhangxingxia 已提交
633

H
HelloCrease 已提交
634 635
  | 类型                                 | 说明     |
  | ---------------------------------- | ------ |
H
haonan_7 已提交
636
  | Promise&lt;[ReadOut](#readout)&gt; | Promise对象。返回读取的结果。 |
Z
zengyawen 已提交
637

Z
zhangxingxia 已提交
638
**示例:**
Z
zhangxingxia 已提交
639
  ```js
Z
zengyawen 已提交
640 641
  let fd = fileio.openSync(path, 0o2);
  let buf = new ArrayBuffer(4096);
Z
zhangxingxia 已提交
642
  fileio.read(fd, buf).then(function(readOut){
H
haonan_7 已提交
643
      console.info("read file data succeed");
Z
zhangxingxia 已提交
644
      console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
Z
zhangxingxia 已提交
645 646
  }).catch(function(err){
      console.info("read file data failed with error:"+ err);
Z
zhangxingxia 已提交
647
  });
Z
zengyawen 已提交
648 649 650
  ```


Z
zengyawen 已提交
651
## fileio.read
Z
zengyawen 已提交
652

653 654 655 656 657
read(fd: number, buffer: ArrayBuffer, options: {
    offset?: number;
    length?: number;
    position?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void
Z
zengyawen 已提交
658

H
haonan_7 已提交
659
从文件读取数据,使用callback异步回调。
Z
zengyawen 已提交
660

661 662
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
663
**参数:**
H
HelloCrease 已提交
664 665 666 667
  | 参数名      | 类型                                       | 必填   | 说明                                       |
  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
  | fd       | number                                   | 是    | 待读取文件的文件描述符。                             |
  | buffer   | ArrayBuffer                              | 是    | 用于保存读取到的文件数据的缓冲区。                        |
Z
zhangxingxia 已提交
668
  | options  | Object                                   | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>约束:offset+length<=buffer.size。  |
H
HelloCrease 已提交
669
  | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | 是    | 异步读取数据之后的回调。                             |
Z
zengyawen 已提交
670

Z
zhangxingxia 已提交
671
**示例:**
Z
zhangxingxia 已提交
672
  ```js
Z
zengyawen 已提交
673 674
  let fd = fileio.openSync(path, 0o2);
  let buf = new ArrayBuffer(4096);
Z
zhangxingxia 已提交
675
  fileio.read(fd, buf, function (err, readOut) {
Z
zhangxingxia 已提交
676
      if (readOut) {
H
haonan_7 已提交
677
          console.info("read file data succeed");
Z
zhangxingxia 已提交
678
          console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
Z
zengyawen 已提交
679 680
      }
  });
Z
zengyawen 已提交
681
  ```
Z
zengyawen 已提交
682 683


Z
zengyawen 已提交
684
## fileio.readSync
Z
zengyawen 已提交
685

686 687 688 689 690
readSync(fd: number, buffer: ArrayBuffer, options?: {
    offset?: number;
    length?: number;
    position?: number;
}): number
Z
zengyawen 已提交
691 692 693

以同步方法从文件读取数据。

694 695
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
696
**参数:**
H
HelloCrease 已提交
697 698 699 700
  | 参数名     | 类型          | 必填   | 说明                                       |
  | ------- | ----------- | ---- | ---------------------------------------- |
  | fd      | number      | 是    | 待读取文件的文件描述符。                             |
  | buffer  | ArrayBuffer | 是    | 用于保存读取到的文件数据的缓冲区。                        |
Z
zhangxingxia 已提交
701
  | options | Object      | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>约束:offset+length<=buffer.size。  |
Z
zengyawen 已提交
702

Z
zhangxingxia 已提交
703
**返回值:**
H
HelloCrease 已提交
704 705
  | 类型     | 说明       |
  | ------ | -------- |
Z
zengyawen 已提交
706 707
  | number | 实际读取的长度。 |

Z
zhangxingxia 已提交
708
**示例:**
Z
zhangxingxia 已提交
709
  ```js
Z
zengyawen 已提交
710 711 712 713 714 715 716 717 718 719
  let fd = fileio.openSync(path, 0o2);
  let buf = new ArrayBuffer(4096);
  let num = fileio.readSync(fd, buf);
  ```


## fileio.rmdir<sup>7+</sup>

rmdir(path: string): Promise&lt;void&gt;

H
haonan_7 已提交
720
删除目录,使用Promise异步回调。
Z
zengyawen 已提交
721

722 723
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
724
**参数:**
Z
zengyawen 已提交
725 726 727
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待删除目录的应用沙箱路径。 |
Z
zengyawen 已提交
728

Z
zhangxingxia 已提交
729
**返回值:**
H
HelloCrease 已提交
730 731
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
732
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
733

Z
zhangxingxia 已提交
734
**示例:**
Z
zhangxingxia 已提交
735 736
  ```js
  fileio.rmdir(path).then(function() {
H
haonan_7 已提交
737
      console.info("rmdir succeed");
Z
zhangxingxia 已提交
738 739
  }).catch(function(err){
      console.info("rmdir failed with error:"+ err);
Z
zengyawen 已提交
740 741 742 743 744 745 746 747
  });
  ```


## fileio.rmdir<sup>7+</sup>

rmdir(path: string, callback:AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
748
删除目录,使用callback异步回调。
Z
zengyawen 已提交
749

750 751
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
752
**参数:**
Z
zengyawen 已提交
753 754 755 756
| 参数名   | 类型                      | 必填 | 说明                       |
| -------- | ------------------------- | ---- | -------------------------- |
| path     | string                    | 是   | 待删除目录的应用沙箱路径。 |
| callback | AsyncCallback&lt;void&gt; | 是   | 异步删除目录之后的回调。   |
Z
zengyawen 已提交
757

Z
zhangxingxia 已提交
758
**示例:**
Z
zhangxingxia 已提交
759 760 761
  ```js
  fileio.rmdir(path, function(err){
      // do something
H
haonan_7 已提交
762
      console.info("rmdir succeed");
Z
zengyawen 已提交
763 764 765 766
  });
  ```


767
## fileio.rmdirSync<sup>7+</sup>
Z
zengyawen 已提交
768

769
rmdirSync(path: string): void
Z
zengyawen 已提交
770 771 772

以同步方法删除目录。

773 774
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
775
**参数:**
Z
zengyawen 已提交
776 777 778
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待删除目录的应用沙箱路径。 |
Z
zengyawen 已提交
779

Z
zhangxingxia 已提交
780
**示例:**
Z
zhangxingxia 已提交
781
  ```js
Z
zengyawen 已提交
782 783 784 785 786 787 788 789
  fileio.rmdirSync(path);
  ```


## fileio.unlink

unlink(path:string): Promise&lt;void&gt;

H
haonan_7 已提交
790
删除文件,使用Promise异步回调。
Z
zengyawen 已提交
791

792 793
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
794
**参数:**
Z
zengyawen 已提交
795 796 797
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待删除文件的应用沙箱路径。 |
Z
zengyawen 已提交
798

Z
zhangxingxia 已提交
799
**返回值:**
H
HelloCrease 已提交
800 801
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
802
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
803

Z
zhangxingxia 已提交
804
**示例:**
Z
zhangxingxia 已提交
805 806
  ```js
  fileio.unlink(path).then(function(){
H
haonan_7 已提交
807
      console.info("remove file succeed");
Z
zhangxingxia 已提交
808 809 810
  }).catch(function(error){
      console.info("remove file failed with error:"+ error);
  });
Z
zengyawen 已提交
811 812 813 814 815 816 817
  ```


## fileio.unlink

unlink(path:string, callback:AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
818
删除文件,使用callback异步回调。
Z
zengyawen 已提交
819

820 821
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
822
**参数:**
Z
zengyawen 已提交
823 824 825 826
| 参数名   | 类型                      | 必填 | 说明                       |
| -------- | ------------------------- | ---- | -------------------------- |
| path     | string                    | 是   | 待删除文件的应用沙箱路径。 |
| callback | AsyncCallback&lt;void&gt; | 是   | 异步删除文件之后的回调。   |
Z
zengyawen 已提交
827

Z
zhangxingxia 已提交
828
**示例:**
Z
zhangxingxia 已提交
829 830
  ```js
  fileio.unlink(path, function(err) {
H
haonan_7 已提交
831
      console.info("remove file succeed");
Z
zengyawen 已提交
832 833 834 835 836 837 838 839 840 841
  });
  ```


## fileio.unlinkSync

unlinkSync(path: string): void

以同步方法删除文件。

842 843
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
844
**参数:**
Z
zengyawen 已提交
845 846 847
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待删除文件的应用沙箱路径。 |
Z
zengyawen 已提交
848

Z
zhangxingxia 已提交
849
**示例:**
Z
zhangxingxia 已提交
850
  ```js
Z
zengyawen 已提交
851 852 853 854 855 856
  fileio.unlinkSync(path);
  ```


## fileio.write

857 858 859 860 861 862
write(fd: number, buffer: ArrayBuffer | string, options?: {
    offset?: number;
    length?: number;
    position?: number;
    encoding?: string;
}): Promise&lt;number&gt;
Z
zengyawen 已提交
863

H
haonan_7 已提交
864
将数据写入文件,使用Promise异步回调。
Z
zengyawen 已提交
865

866 867
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
868
**参数:**
H
HelloCrease 已提交
869 870 871 872
  | 参数名     | 类型                              | 必填   | 说明                                       |
  | ------- | ------------------------------- | ---- | ---------------------------------------- |
  | fd      | number                          | 是    | 待写入文件的文件描述符。                             |
  | buffer  | ArrayBuffer&nbsp;\|&nbsp;string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
Z
zhangxingxia 已提交
873
  | options | Object                          | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。仅支持&nbsp;'utf-8'。<br/>约束:offset+length<=buffer.size。 |
Z
zengyawen 已提交
874

Z
zhangxingxia 已提交
875
**返回值:**
H
HelloCrease 已提交
876 877
  | 类型                    | 说明       |
  | --------------------- | -------- |
H
haonan_7 已提交
878
  | Promise&lt;number&gt; | Promise对象。返回实际写入的长度。 |
Z
zengyawen 已提交
879

Z
zhangxingxia 已提交
880
**示例:**
Z
zhangxingxia 已提交
881
  ```js
Z
zhangxingxia 已提交
882
  let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
Z
zhangxingxia 已提交
883
  fileio.write(fd, "hello, world").then(function(number){
H
haonan_7 已提交
884
       console.info("write data to file succeed and size is:"+ number);
Z
zhangxingxia 已提交
885 886 887
  }).catch(function(err){
      console.info("write data to file failed with error:"+ err);
  });
Z
zengyawen 已提交
888 889 890 891 892
  ```


## fileio.write

893 894 895 896 897 898
write(fd: number, buffer: ArrayBuffer | string, options: {
    offset?: number;
    length?: number;
    position?: number;
    encoding?: string;
}, callback: AsyncCallback&lt;number&gt;): void
Z
zengyawen 已提交
899

H
haonan_7 已提交
900
将数据写入文件,使用callback异步回调。
Z
zengyawen 已提交
901

902 903
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
904
**参数:**
H
HelloCrease 已提交
905 906 907 908
  | 参数名      | 类型                              | 必填   | 说明                                       |
  | -------- | ------------------------------- | ---- | ---------------------------------------- |
  | fd       | number                          | 是    | 待写入文件的文件描述符。                             |
  | buffer   | ArrayBuffer&nbsp;\|&nbsp;string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
Z
zhangxingxia 已提交
909
  | options  | Object                          | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。仅支持&nbsp;'utf-8'。<br/>约束:offset+length<=buffer.size。 |
H
HelloCrease 已提交
910
  | callback | AsyncCallback&lt;number&gt;     | 是    | 异步将数据写入完成后执行的回调函数。                       |
Z
zengyawen 已提交
911

Z
zhangxingxia 已提交
912
**示例:**
Z
zhangxingxia 已提交
913
  ```js
Z
zengyawen 已提交
914 915
  let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
  fileio.write(fd, "hello, world", function (err, bytesWritten) {
Z
zhangxingxia 已提交
916
      if (bytesWritten) {
H
haonan_7 已提交
917
         console.info("write data to file succeed and size is:"+ bytesWritten);
Z
zengyawen 已提交
918 919 920 921 922 923 924
      }
  });
  ```


## fileio.writeSync

925 926 927 928 929 930
writeSync(fd: number, buffer: ArrayBuffer | string, options?: {
    offset?: number;
    length?: number;
    position?: number;
    encoding?: string;
}): number
Z
zengyawen 已提交
931 932 933

以同步方法将数据写入文件。

934 935
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
936
**参数:**
H
HelloCrease 已提交
937 938 939 940
  | 参数名     | 类型                              | 必填   | 说明                                       |
  | ------- | ------------------------------- | ---- | ---------------------------------------- |
  | fd      | number                          | 是    | 待写入文件的文件描述符。                             |
  | buffer  | ArrayBuffer&nbsp;\|&nbsp;string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
Z
zhangxingxia 已提交
941
  | options | Object                          | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。仅支持&nbsp;'utf-8'。<br/>约束:offset+length<=buffer.size。 |
Z
zengyawen 已提交
942

Z
zhangxingxia 已提交
943
**返回值:**
H
HelloCrease 已提交
944 945
  | 类型     | 说明       |
  | ------ | -------- |
Z
zengyawen 已提交
946 947
  | number | 实际写入的长度。 |

Z
zhangxingxia 已提交
948
**示例:**
Z
zhangxingxia 已提交
949
  ```js
Z
zengyawen 已提交
950 951 952 953 954 955 956 957 958
  let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
  let num = fileio.writeSync(fd, "hello, world");
  ```


## fileio.hash

hash(path: string, algorithm: string): Promise&lt;string&gt;

H
haonan_7 已提交
959
计算文件的哈希值,使用Promise异步回调。
Z
zengyawen 已提交
960

961 962
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
963
**参数:**
Z
zengyawen 已提交
964 965 966 967
| 参数名    | 类型   | 必填 | 说明                                                         |
| --------- | ------ | ---- | ------------------------------------------------------------ |
| path      | string | 是   | 待计算哈希值文件的应用沙箱路径。                             |
| algorithm | string | 是   | 哈希计算采用的算法。可选&nbsp;"md5"、"sha1"&nbsp;&nbsp;"sha256"。建议采用安全强度更高的&nbsp;"sha256"。 |
Z
zengyawen 已提交
968

Z
zhangxingxia 已提交
969
**返回值:**
H
HelloCrease 已提交
970 971
  | 类型                    | 说明                         |
  | --------------------- | -------------------------- |
H
haonan_7 已提交
972
  | Promise&lt;string&gt; | Promise对象。返回文件的哈希值。表示为十六进制数字串,所有字母均大写。 |
Z
zengyawen 已提交
973

Z
zhangxingxia 已提交
974
**示例:**
Z
zhangxingxia 已提交
975 976
  ```js
  fileio.hash(path, "sha256").then(function(str){
H
haonan_7 已提交
977
      console.info("calculate file hash succeed:"+ str);
Z
zhangxingxia 已提交
978
  }).catch(function(error){
W
wangbo 已提交
979
      console.info("calculate file hash failed with error:"+ err);
Z
zhangxingxia 已提交
980
  });
Z
zengyawen 已提交
981 982 983 984 985
  ```


## fileio.hash

986
hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): void
Z
zengyawen 已提交
987

H
haonan_7 已提交
988
计算文件的哈希值,使用callback异步回调。
Z
zengyawen 已提交
989

990 991
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
992
**参数:**
Z
zengyawen 已提交
993 994 995 996
| 参数名    | 类型                        | 必填 | 说明                                                         |
| --------- | --------------------------- | ---- | ------------------------------------------------------------ |
| path      | string                      | 是   | 待计算哈希值文件的应用沙箱路径。                             |
| algorithm | string                      | 是   | 哈希计算采用的算法。可选&nbsp;"md5"、"sha1"&nbsp;&nbsp;"sha256"。建议采用安全强度更高的&nbsp;"sha256"。 |
H
haonan_7 已提交
997
| callback  | AsyncCallback&lt;string&gt; | 是   | 异步计算文件哈希操作之后的回调函数(其中给定文件哈希值表示为十六进制数字串,所有字母均大写)。 |
Z
zengyawen 已提交
998

Z
zhangxingxia 已提交
999
**示例:**
Z
zhangxingxia 已提交
1000
  ```js
Z
zhangxingxia 已提交
1001
  fileio.hash(path, "sha256", function(err, hashStr) {
Z
zhangxingxia 已提交
1002
      if (hashStr) {
H
haonan_7 已提交
1003
          console.info("calculate file hash succeed:"+ hashStr);
Z
zengyawen 已提交
1004 1005 1006 1007 1008 1009 1010 1011 1012
      }
  });
  ```


## fileio.chmod<sup>7+</sup>

chmod(path: string, mode: number):Promise&lt;void&gt;

H
haonan_7 已提交
1013
改变文件权限,使用Promise异步回调。
Z
zengyawen 已提交
1014

1015 1016
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1017
**参数:**
Z
zengyawen 已提交
1018 1019
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
H
haonan_7 已提交
1020
| path   | string | 是   | 所需变更权限的文件的应用沙箱路径。                               |
Z
zengyawen 已提交
1021
| mode   | number | 是   | 改变文件权限,可给定如下权限,以按位或的方式追加权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
Z
zengyawen 已提交
1022

Z
zhangxingxia 已提交
1023
**返回值:**
H
HelloCrease 已提交
1024 1025
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
1026
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
1027

Z
zhangxingxia 已提交
1028
**示例:**
Z
zhangxingxia 已提交
1029
  ```js
W
wangbo 已提交
1030
  fileio.chmod(path, mode).then(function() {
H
haonan_7 已提交
1031
      console.info("chmod succeed");
Z
zhangxingxia 已提交
1032 1033
  }).catch(function(err){
      console.info("chmod failed with error:"+ err);
Z
zengyawen 已提交
1034 1035 1036 1037 1038 1039 1040 1041
  });
  ```


## fileio.chmod<sup>7+</sup>

chmod(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
1042
改变文件权限,使用callback异步回调。
Z
zengyawen 已提交
1043

1044 1045
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1046
**参数:**
Z
zengyawen 已提交
1047 1048
| 参数名   | 类型                      | 必填 | 说明                                                         |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
H
haonan_7 已提交
1049
| path     | string                    | 是   | 所需变更权限的文件的应用沙箱路径。                               |
Z
zengyawen 已提交
1050 1051
| mode     | number                    | 是   | 改变文件权限,可给定如下权限,以按位或的方式追加权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
| callback | AsyncCallback&lt;void&gt; | 是   | 异步改变文件权限之后的回调。                                 |
Z
zengyawen 已提交
1052

Z
zhangxingxia 已提交
1053
**示例:**
Z
zhangxingxia 已提交
1054
  ```js
W
wangbo 已提交
1055
  fileio.chmod(path, mode, function (err) {
Z
zhangxingxia 已提交
1056
      // do something
Z
zengyawen 已提交
1057 1058 1059 1060 1061 1062 1063 1064
  });
  ```


## fileio.chmodSync<sup>7+</sup>

chmodSync(path: string, mode: number): void

H
haonan_7 已提交
1065
以同步方法改变文件权限。
Z
zengyawen 已提交
1066

1067 1068
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1069
**参数:**
Z
zengyawen 已提交
1070 1071
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
H
haonan_7 已提交
1072
| path   | string | 是   | 所需变更权限的文件的应用沙箱路径。                               |
Z
zengyawen 已提交
1073
| mode   | number | 是   | 改变文件权限,可给定如下权限,以按位或的方式追加权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
Z
zengyawen 已提交
1074

Z
zhangxingxia 已提交
1075
**示例:**
Z
zhangxingxia 已提交
1076
  ```js
Z
zhangxingxia 已提交
1077
  fileio.chmodSync(path, mode);
Z
zengyawen 已提交
1078 1079 1080 1081 1082 1083 1084
  ```


## fileio.fstat<sup>7+</sup>

fstat(fd: number): Promise&lt;Stat&gt;

H
haonan_7 已提交
1085
基于文件描述符获取文件状态信息,使用Promise异步回调。
Z
zengyawen 已提交
1086

1087 1088
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1089
**参数:**
H
HelloCrease 已提交
1090 1091
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
H
haonan_7 已提交
1092
  | fd   | number | 是    | 待获取文件状态的文件描述符。 |
Z
zengyawen 已提交
1093

Z
zhangxingxia 已提交
1094
**返回值:**
H
HelloCrease 已提交
1095 1096
  | 类型                           | 说明         |
  | ---------------------------- | ---------- |
H
haonan_7 已提交
1097
  | Promise&lt;[Stat](#stat)&gt; | Promise对象。返回表示文件状态的具体信息。 |
Z
zengyawen 已提交
1098

Z
zhangxingxia 已提交
1099
**示例:**
Z
zhangxingxia 已提交
1100 1101
  ```js
  fileio.fstat(fd).then(function(stat){
H
haonan_7 已提交
1102
      console.info("fstat succeed:"+ JSON.stringify(stat));
Z
zhangxingxia 已提交
1103 1104 1105
  }).catch(function(err){
      console.info("fstat failed with error:"+ err);
  });
Z
zengyawen 已提交
1106 1107 1108 1109 1110 1111 1112
  ```


## fileio.fstat<sup>7+</sup>

fstat(fd: number, callback: AsyncCallback&lt;Stat&gt;): void

H
haonan_7 已提交
1113
基于文件描述符获取文件状态信息,使用callback异步回调。
Z
zengyawen 已提交
1114

1115 1116
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1117
**参数:**
H
HelloCrease 已提交
1118 1119
  | 参数名      | 类型                                 | 必填   | 说明               |
  | -------- | ---------------------------------- | ---- | ---------------- |
H
haonan_7 已提交
1120 1121
  | fd       | number                             | 是    | 待获取文件状态的文件描述符。     |
  | callback | AsyncCallback&lt;[Stat](#stat)&gt; | 是    | 异步获取文件状态信息之后的回调。 |
Z
zengyawen 已提交
1122

Z
zhangxingxia 已提交
1123
**示例:**
Z
zhangxingxia 已提交
1124
  ```js
Z
zengyawen 已提交
1125
  let fd = fileio.openSync(path);
Z
zhangxingxia 已提交
1126 1127
  fileio.fstat(fd, function (err) {
      // do something
Z
zengyawen 已提交
1128 1129 1130 1131 1132 1133 1134 1135
  });
  ```


## fileio.fstatSync<sup>7+</sup>

fstatSync(fd: number): Stat

H
haonan_7 已提交
1136
以同步方法基于文件描述符获取文件状态信息。
Z
zengyawen 已提交
1137

1138 1139
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1140
**参数:**
H
HelloCrease 已提交
1141 1142
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
H
haonan_7 已提交
1143
  | fd   | number | 是    | 待获取文件状态的文件描述符。 |
Z
zengyawen 已提交
1144

Z
zhangxingxia 已提交
1145
**返回值:**
H
HelloCrease 已提交
1146 1147
  | 类型            | 说明         |
  | ------------- | ---------- |
H
haonan_7 已提交
1148
  | [Stat](#stat) | 表示文件状态的具体信息。 |
Z
zengyawen 已提交
1149

Z
zhangxingxia 已提交
1150
**示例:**
Z
zhangxingxia 已提交
1151
  ```js
Z
zengyawen 已提交
1152 1153 1154 1155 1156 1157 1158
  let fd = fileio.openSync(path);
  let stat = fileio.fstatSync(fd);
  ```


## fileio.ftruncate<sup>7+</sup>

1159
ftruncate(fd: number, len?: number): Promise&lt;void&gt;
Z
zengyawen 已提交
1160

H
haonan_7 已提交
1161
基于文件描述符截断文件,使用Promise异步回调。
Z
zengyawen 已提交
1162

1163 1164
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1165
**参数:**
H
HelloCrease 已提交
1166 1167 1168
  | 参数名  | 类型     | 必填   | 说明               |
  | ---- | ------ | ---- | ---------------- |
  | fd   | number | 是    | 待截断文件的文件描述符。     |
H
haonan_7 已提交
1169
  | len  | number | 否    | 文件截断后的长度,以字节为单位。 |
Z
zengyawen 已提交
1170

Z
zhangxingxia 已提交
1171
**返回值:**
H
HelloCrease 已提交
1172 1173
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
1174
  | Promise&lt;void&gt; | Promise对象。无返回值。|
Z
zengyawen 已提交
1175

Z
zhangxingxia 已提交
1176
**示例:**
Z
zhangxingxia 已提交
1177
  ```js
Z
zengyawen 已提交
1178
  let fd = fileio.openSync(path);
Z
zhangxingxia 已提交
1179
  fileio.ftruncate(fd, 5).then(function(err) {    
H
haonan_7 已提交
1180
      console.info("truncate file succeed");
Z
zhangxingxia 已提交
1181 1182
  }).catch(function(err){
      console.info("truncate file failed with error:"+ err);
Z
zengyawen 已提交
1183 1184 1185 1186 1187 1188 1189 1190
  });
  ```


## fileio.ftruncate<sup>7+</sup>

ftruncate(fd: number, len: number, callback:AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
1191
基于文件描述符截断文件,使用callback异步回调。
Z
zengyawen 已提交
1192

1193 1194
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1195
**参数:**
H
HelloCrease 已提交
1196 1197 1198 1199
  | 参数名      | 类型                        | 必填   | 说明               |
  | -------- | ------------------------- | ---- | ---------------- |
  | fd       | number                    | 是    | 待截断文件的文件描述符。     |
  | len      | number                    | 是    | 文件截断后的长度,以字节为单位。 |
W
wangbo 已提交
1200
  | callback | AsyncCallback&lt;void&gt; | 是    | 回调函数,本调用无返回值。  |
Z
zengyawen 已提交
1201

Z
zhangxingxia 已提交
1202
**示例:**
Z
zhangxingxia 已提交
1203 1204 1205
  ```js
  fileio.ftruncate(fd, len, function(err){
      // do something
Z
zengyawen 已提交
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
  });
  ```


## fileio.ftruncateSync<sup>7+</sup>

ftruncateSync(fd: number, len?: number): void

以同步方法基于文件描述符截断文件。

1216 1217
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1218
**参数:**
H
HelloCrease 已提交
1219 1220 1221 1222
  | 参数名  | 类型     | 必填   | 说明               |
  | ---- | ------ | ---- | ---------------- |
  | fd   | number | 是    | 待截断文件的文件描述符。     |
  | len  | number | 否    | 文件截断后的长度,以字节为单位。 |
Z
zengyawen 已提交
1223

Z
zhangxingxia 已提交
1224
**示例:**
Z
zhangxingxia 已提交
1225
  ```js
Z
zhangxingxia 已提交
1226
  fileio.ftruncateSync(fd, len);
Z
zengyawen 已提交
1227 1228 1229 1230 1231
  ```


## fileio.truncate<sup>7+</sup>

1232
truncate(path: string, len?: number): Promise&lt;void&gt;
Z
zengyawen 已提交
1233

H
haonan_7 已提交
1234
基于文件路径截断文件,使用Promise异步回调。
Z
zengyawen 已提交
1235

1236 1237
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1238
**参数:**
Z
zengyawen 已提交
1239 1240 1241
| 参数名 | 类型   | 必填 | 说明                             |
| ------ | ------ | ---- | -------------------------------- |
| path   | string | 是   | 待截断文件的应用沙箱路径。       |
H
haonan_7 已提交
1242
| len    | number | 否   | 文件截断后的长度,以字节为单位。 |
Z
zengyawen 已提交
1243

Z
zhangxingxia 已提交
1244
**返回值:**
H
HelloCrease 已提交
1245 1246
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
1247
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
1248

Z
zhangxingxia 已提交
1249
**示例:**
Z
zhangxingxia 已提交
1250 1251
  ```js
  fileio.truncate(path, len).then(function(){
H
haonan_7 已提交
1252
      console.info("truncate file succeed");
Z
zhangxingxia 已提交
1253 1254
  }).catch(function(err){
      console.info("truncate file failed with error:"+ err);
Z
zengyawen 已提交
1255 1256 1257 1258 1259 1260 1261 1262
  });
  ```


## fileio.truncate<sup>7+</sup>

truncate(path: string, len: number, callback:AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
1263
基于文件路径截断文件,使用callback异步回调。
Z
zengyawen 已提交
1264

1265 1266
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1267
**参数:**
Z
zengyawen 已提交
1268 1269 1270 1271
| 参数名   | 类型                      | 必填 | 说明                             |
| -------- | ------------------------- | ---- | -------------------------------- |
| path     | string                    | 是   | 待截断文件的应用沙箱路径。       |
| len      | number                    | 是   | 文件截断后的长度,以字节为单位。 |
W
wangbo 已提交
1272
| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数,本调用无返回值。   |
Z
zengyawen 已提交
1273

Z
zhangxingxia 已提交
1274
**示例:**
Z
zhangxingxia 已提交
1275 1276 1277
  ```js
  fileio.truncate(path, len, function(err){
      // do something
Z
zengyawen 已提交
1278 1279 1280 1281 1282 1283
  });
  ```


## fileio.truncateSync<sup>7+</sup>

1284
truncateSync(path: string, len?: number): void
Z
zengyawen 已提交
1285 1286 1287

以同步方法基于文件路径截断文件。

1288 1289
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1290
**参数:**
Z
zengyawen 已提交
1291 1292 1293 1294
| 参数名 | 类型   | 必填 | 说明                             |
| ------ | ------ | ---- | -------------------------------- |
| path   | string | 是   | 待截断文件的应用沙箱路径。       |
| len    | number | 否   | 文件截断后的长度,以字节为单位。 |
Z
zengyawen 已提交
1295

Z
zhangxingxia 已提交
1296
**示例:**
Z
zhangxingxia 已提交
1297
  ```js
Z
zhangxingxia 已提交
1298
  fileio.truncateSync(path, len);
Z
zengyawen 已提交
1299 1300 1301 1302 1303
  ```


## fileio.readText<sup>7+</sup>

1304 1305 1306 1307 1308
readText(filePath: string, options?: {
    position?: number;
    length?: number;
    encoding?: string;
}): Promise&lt;string&gt;
Z
zengyawen 已提交
1309

H
haonan_7 已提交
1310
基于文本方式读取文件(即直接读取文件的文本内容),使用Promise异步回调。
Z
zengyawen 已提交
1311

1312 1313
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1314
**参数:**
Z
zengyawen 已提交
1315 1316 1317 1318
| 参数名   | 类型   | 必填 | 说明                                                         |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | 是   | 待读取文件的应用沙箱路径。                                   |
| options  | Object | 否   | 支持如下选项:<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;encoding,string类型,当数据是&nbsp;string&nbsp;类型时有效,表示数据的编码方式,默认&nbsp;'utf-8',仅支持&nbsp;'utf-8'。 |
Z
zengyawen 已提交
1319

Z
zhangxingxia 已提交
1320
**返回值:**
H
HelloCrease 已提交
1321 1322
  | 类型                    | 说明         |
  | --------------------- | ---------- |
H
haonan_7 已提交
1323
  | Promise&lt;string&gt; | Promise对象。返回读取文件的内容。 |
Z
zengyawen 已提交
1324

Z
zhangxingxia 已提交
1325
**示例:**
Z
zhangxingxia 已提交
1326 1327
  ```js
  fileio.readText(path).then(function(str) {
H
haonan_7 已提交
1328
      console.info("readText succeed:"+ str);
Z
zhangxingxia 已提交
1329 1330
  }).catch(function(err){
      console.info("readText failed with error:"+ err);
Z
zengyawen 已提交
1331 1332 1333 1334 1335 1336
  });
  ```


## fileio.readText<sup>7+</sup>

1337 1338 1339 1340 1341
readText(filePath: string, options: {
    position?: number;
    length?: number;
    encoding?: string;
}, callback: AsyncCallback&lt;string&gt;): void
Z
zengyawen 已提交
1342

H
haonan_7 已提交
1343
基于文本方式读取文件(即直接读取文件的文本内容),使用callback异步回调。
Z
zengyawen 已提交
1344

1345 1346
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1347
**参数:**
Z
zengyawen 已提交
1348 1349 1350
| 参数名   | 类型                        | 必填 | 说明                                                         |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string                      | 是   | 待读取文件的应用沙箱路径。                                   |
W
wangbo 已提交
1351 1352
| options  | Object                      | 否   | 支持如下选项:<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;encoding,string类型,表示数据的编码方式,默认&nbsp;'utf-8',仅支持&nbsp;'utf-8'。 |
| callback | AsyncCallback&lt;string&gt; | 是   | 回调函数,返回读取文件的内容。                         |
Z
zengyawen 已提交
1353

Z
zhangxingxia 已提交
1354
**示例:**
Z
zhangxingxia 已提交
1355
  ```js
W
wangbo 已提交
1356
  fileio.readText(path, function(err, str){
Z
zhangxingxia 已提交
1357
      // do something
Z
zengyawen 已提交
1358 1359 1360 1361 1362 1363
  });
  ```


## fileio.readTextSync<sup>7+</sup>

1364 1365 1366 1367 1368
readTextSync(filePath: string, options?: {
    position?: number;
    length?: number;
    encoding?: string;
}): string
Z
zengyawen 已提交
1369 1370 1371

以同步方法基于文本方式读取文件(即直接读取文件的文本内容)。

1372 1373
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1374
**参数:**
Z
zengyawen 已提交
1375 1376 1377 1378
| 参数名   | 类型   | 必填 | 说明                                                         |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | 是   | 待读取文件的应用沙箱路径。                                   |
| options  | Object | 否   | 支持如下选项:<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;encoding,string类型,当数据是&nbsp;string&nbsp;类型时有效,表示数据的编码方式,默认&nbsp;'utf-8',仅支持&nbsp;'utf-8'。 |
Z
zengyawen 已提交
1379

Z
zhangxingxia 已提交
1380
**返回值:**
Z
zhangxingxia 已提交
1381 1382 1383
  | 类型   | 说明                 |
  | ------ | -------------------- |
  | string | 返回读取文件的内容。 |
Z
zengyawen 已提交
1384

Z
zhangxingxia 已提交
1385
**示例:**
Z
zhangxingxia 已提交
1386 1387
  ```js
  let str = fileio.readTextSync(path, {position: 1, length: 3});
Z
zengyawen 已提交
1388 1389 1390 1391 1392 1393 1394
  ```


## fileio.lstat<sup>7+</sup>

lstat(path: string): Promise&lt;Stat&gt;

H
haonan_7 已提交
1395
获取链接信息,使用Promise异步回调。
Z
zengyawen 已提交
1396

1397 1398
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1399
**参数:**
Z
zengyawen 已提交
1400 1401
| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
W
wangbo 已提交
1402
| path   | string | 是   | 目标文件的应用沙箱路径。 |
Z
zengyawen 已提交
1403

Z
zhangxingxia 已提交
1404
**返回值:**
H
HelloCrease 已提交
1405 1406
  | 类型                           | 说明         |
  | ---------------------------- | ---------- |
W
wangbo 已提交
1407
  | Promise&lt;[Stat](#stat)&gt; | promise对象,返回文件对象,表示文件的具体信息,详情见stat。 |
Z
zengyawen 已提交
1408

Z
zhangxingxia 已提交
1409
**示例:**
Z
zhangxingxia 已提交
1410 1411
  ```js
  fileio.lstat(path).then(function(stat){
Z
zhangxingxia 已提交
1412
      console.info("get link status succeed:"+ JSON.stringify(stat));
Z
zhangxingxia 已提交
1413 1414 1415
  }).catch(function(err){
      console.info("get link status failed with error:"+ err);
  });
Z
zengyawen 已提交
1416 1417 1418 1419 1420 1421 1422
  ```


## fileio.lstat<sup>7+</sup>

lstat(path:string, callback:AsyncCallback&lt;Stat&gt;): void

H
haonan_7 已提交
1423
获取链接信息,使用callback异步回调。
Z
zengyawen 已提交
1424

1425 1426
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1427
**参数:**
Z
zengyawen 已提交
1428 1429
| 参数名   | 类型                               | 必填 | 说明                                   |
| -------- | ---------------------------------- | ---- | -------------------------------------- |
W
wangbo 已提交
1430 1431
| path     | string                             | 是   | 目标文件的应用沙箱路径。 |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | 是   | 回调函数,返回文件的具体信息。       |
Z
zengyawen 已提交
1432

Z
zhangxingxia 已提交
1433
**示例:**
Z
zhangxingxia 已提交
1434 1435 1436
  ```js
  fileio.lstat(path, function (err, stat) {
      // do something
Z
zengyawen 已提交
1437
  });
Z
zengyawen 已提交
1438 1439 1440 1441 1442 1443 1444
  ```


## fileio.lstatSync<sup>7+</sup>

lstatSync(path:string): Stat

1445
以同步方法获取链接信息。
Z
zengyawen 已提交
1446

1447 1448
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1449
**参数:**
Z
zengyawen 已提交
1450 1451
| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
W
wangbo 已提交
1452
| path   | string | 是   | 目标文件的应用沙箱路径。 |
Z
zengyawen 已提交
1453

Z
zhangxingxia 已提交
1454
**返回值:**
H
HelloCrease 已提交
1455 1456
  | 类型            | 说明         |
  | ------------- | ---------- |
Z
zengyawen 已提交
1457 1458
  | [Stat](#stat) | 表示文件的具体信息。 |

Z
zhangxingxia 已提交
1459
**示例:**
Z
zhangxingxia 已提交
1460
  ```js
Z
zengyawen 已提交
1461 1462 1463 1464
  let stat = fileio.lstatSync(path);
  ```


W
wangbo 已提交
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527
## fileio.read<sup>7+</sup>

read(buffer: ArrayBuffer, options?: {
    position?: number;
    offset?: number;
    length?: number;
}): Promise&lt;ReadOut&gt;

从文件读取数据,使用Promise异步回调。

**系统能力**:SystemCapability.FileManagement.File.FileIO

**参数:**
  | 参数名  | 类型        | 必填 | 说明                                                         |
  | ------- | ----------- | ---- | ------------------------------------------------------------ |
  | buffer  | ArrayBuffer | 是   | 用于保存读取到的文件数据的缓冲区。                           |
  | options | Object      | 否   | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>约束:offset+length<=buffer.size。 |

**返回值:**
  | 类型                                 | 说明     |
  | ---------------------------------- | ------ |
  | Promise&lt;[ReadOut](#readout)&gt; | Promise对象。返回读取的结果。 |

**示例:**
  ```js
  fileio.read(new ArrayBuffer(4096)).then(function(readout){
      console.info("read file data succeed");
      console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
  }).catch(function(err){
      console.info("read file data failed with error:"+ err);
  });
  ```


## fileio.read<sup>7+</sup>

read(buffer: ArrayBuffer, options: {
    position?: number;
    offset?: number;
    length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void

从文件读取数据,使用callback异步回调。

**系统能力**:SystemCapability.FileManagement.File.FileIO

**参数:**
  | 参数名      | 类型                                       | 必填   | 说明                                       |
  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
  | buffer   | ArrayBuffer                              | 是    | 用于保存读取到的文件数据的缓冲区。                        |
  | options  | Object                                   | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>约束:offset+length<=buffer.size。 |
  | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | 是    | 异步从文件读取数据之后的回调。                          |

**示例:**
  ```js
  let buf = new ArrayBuffer(4096);
  fileio.read(buf, function (err, readOut) {
      if (readOut) {
          console.info("read file data succeed");
          console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
      }
  });
  ```
Z
zengyawen 已提交
1528 1529 1530 1531 1532 1533


## fileio.rename<sup>7+</sup>

rename(oldPath: string, newPath: string): Promise&lt;void&gt;

H
haonan_7 已提交
1534
重命名文件,使用Promise异步回调。
Z
zengyawen 已提交
1535

1536 1537
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1538
**参数:**
Z
zengyawen 已提交
1539 1540 1541 1542
| 参数名  | 类型   | 必填 | 说明                         |
| ------- | ------ | ---- | ---------------------------- |
| oldPath | string | 是   | 目标文件的当前应用沙箱路径。 |
| newPath | String | 是   | 目标文件的新应用沙箱路径。   |
Z
zengyawen 已提交
1543

Z
zhangxingxia 已提交
1544
**返回值:**
H
HelloCrease 已提交
1545 1546
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
1547
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
1548

Z
zhangxingxia 已提交
1549
**示例:**
Z
zhangxingxia 已提交
1550
  ```js
W
wangbo 已提交
1551
  fileio.rename(oldPath, newPath).then(function() {
H
haonan_7 已提交
1552
      console.info("rename succeed");
Z
zhangxingxia 已提交
1553 1554
  }).catch(function(err){
      console.info("rename failed with error:"+ err);
Z
zengyawen 已提交
1555 1556 1557 1558 1559 1560 1561 1562
  });
  ```


## fileio.rename<sup>7+</sup>

rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
1563
重命名文件,使用callback异步回调。
Z
zengyawen 已提交
1564

1565 1566
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1567
**参数:**
Z
zengyawen 已提交
1568 1569 1570 1571 1572
| 参数名   | 类型                      | 必填 | 说明                         |
| -------- | ------------------------- | ---- | ---------------------------- |
| oldPath  | string                    | 是   | 目标文件的当前应用沙箱路径。 |
| newPath  | String                    | 是   | 目标文件的新应用沙箱路径。   |
| Callback | AsyncCallback&lt;void&gt; | 是   | 异步重命名文件之后的回调。   |
Z
zengyawen 已提交
1573

Z
zhangxingxia 已提交
1574
**示例:**
Z
zhangxingxia 已提交
1575
  ```js
W
wangbo 已提交
1576
  fileio.rename(oldPath, newPath, function(err){
Z
zengyawen 已提交
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
  });
  ```


## fileio.renameSync<sup>7+</sup>

renameSync(oldPath: string, newPath: string): void

以同步方法重命名文件。

1587 1588
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1589
**参数:**
Z
zengyawen 已提交
1590 1591 1592 1593
| 参数名  | 类型   | 必填 | 说明                         |
| ------- | ------ | ---- | ---------------------------- |
| oldPath | string | 是   | 目标文件的当前应用沙箱路径。 |
| newPath | String | 是   | 目标文件的新应用沙箱路径。   |
Z
zengyawen 已提交
1594

Z
zhangxingxia 已提交
1595
**示例:**
Z
zhangxingxia 已提交
1596
  ```js
W
wangbo 已提交
1597
  fileio.renameSync(oldPath, newPath);
Z
zengyawen 已提交
1598 1599 1600 1601 1602 1603 1604
  ```


## fileio.fsync<sup>7+</sup>

fsync(fd: number): Promise&lt;void&gt;

H
haonan_7 已提交
1605
同步文件数据,使用Promise异步回调。
Z
zengyawen 已提交
1606

1607 1608
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1609
**参数:**
H
HelloCrease 已提交
1610 1611 1612
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
  | fd   | number | 是    | 待同步文件的文件描述符。 |
Z
zengyawen 已提交
1613

Z
zhangxingxia 已提交
1614
**返回值:**
H
HelloCrease 已提交
1615 1616
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
1617
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
1618

Z
zhangxingxia 已提交
1619
**示例:**
Z
zhangxingxia 已提交
1620 1621
  ```js
  fileio.fsync(fd).then(function(){
H
haonan_7 已提交
1622
      console.info("sync data succeed");
Z
zhangxingxia 已提交
1623 1624 1625
  }).catch(function(err){
      console.info("sync data failed with error:"+ err);
  });
Z
zengyawen 已提交
1626 1627 1628 1629 1630 1631 1632
  ```


## fileio.fsync<sup>7+</sup>

fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
1633
同步文件数据,使用callback异步回调。
Z
zengyawen 已提交
1634

1635 1636
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1637
**参数:**
H
HelloCrease 已提交
1638 1639 1640 1641
  | 参数名      | 类型                        | 必填   | 说明              |
  | -------- | ------------------------- | ---- | --------------- |
  | fd       | number                    | 是    | 待同步文件的文件描述符。    |
  | Callback | AsyncCallback&lt;void&gt; | 是    | 异步将文件数据同步之后的回调。 |
Z
zengyawen 已提交
1642

Z
zhangxingxia 已提交
1643
**示例:**
W
wangbo 已提交
1644
  ```js
Z
zengyawen 已提交
1645
  fileio.fsync(fd, function(err){
Z
zhangxingxia 已提交
1646
      // do something
Z
zengyawen 已提交
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
  });
  ```


## fileio.fsyncSync<sup>7+</sup>

fsyncSync(fd: number): void

以同步方法同步文件数据。

1657 1658
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1659
**参数:**
H
HelloCrease 已提交
1660 1661 1662
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
  | fd   | number | 是    | 待同步文件的文件描述符。 |
Z
zengyawen 已提交
1663

Z
zhangxingxia 已提交
1664
**示例:**
Z
zhangxingxia 已提交
1665
  ```js
Z
zhangxingxia 已提交
1666
  fileio.fsyncSync(fd);
Z
zengyawen 已提交
1667 1668 1669 1670 1671 1672 1673
  ```


## fileio.fdatasync<sup>7+</sup>

fdatasync(fd: number): Promise&lt;void&gt;

H
haonan_7 已提交
1674
实现文件内容数据同步,使用Promise异步回调。
Z
zengyawen 已提交
1675

1676 1677
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1678
**参数:**
H
HelloCrease 已提交
1679 1680 1681
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
  | fd   | number | 是    | 待同步文件的文件描述符。 |
Z
zengyawen 已提交
1682

Z
zhangxingxia 已提交
1683
**返回值:**
H
HelloCrease 已提交
1684 1685
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
1686
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
1687

Z
zhangxingxia 已提交
1688
**示例:**
W
wangbo 已提交
1689
  ```js
Z
zhangxingxia 已提交
1690
  fileio.fdatasync(fd).then(function(err) {
H
haonan_7 已提交
1691
      console.info("sync data succeed");
Z
zhangxingxia 已提交
1692 1693
  }).catch(function(err){
      console.info("sync data failed with error:"+ err);
Z
zengyawen 已提交
1694 1695 1696 1697 1698 1699 1700 1701
  });
  ```


## fileio.fdatasync<sup>7+</sup>

fdatasync(fd: number, callback:AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
1702
实现文件内容数据同步,使用callback异步回调。
Z
zengyawen 已提交
1703

1704 1705
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1706
**参数:**
H
HelloCrease 已提交
1707 1708 1709 1710
  | 参数名      | 类型                              | 必填   | 说明                |
  | -------- | ------------------------------- | ---- | ----------------- |
  | fd       | number                          | 是    | 待同步文件的文件描述符。      |
  | callback | AsyncCallback&nbsp;&lt;void&gt; | 是    | 异步将文件内容数据同步之后的回调。 |
Z
zengyawen 已提交
1711

Z
zhangxingxia 已提交
1712
**示例:**
Z
zhangxingxia 已提交
1713
  ```js
Z
zengyawen 已提交
1714
  fileio.fdatasync (fd, function (err) {
Z
zhangxingxia 已提交
1715
      // do something
Z
zengyawen 已提交
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725
  });
  ```


## fileio.fdatasyncSync<sup>7+</sup>

fdatasyncSync(fd: number): void

以同步方法实现文件内容数据同步。

1726 1727
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1728
**参数:**
H
HelloCrease 已提交
1729 1730 1731
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
  | fd   | number | 是    | 待同步文件的文件描述符。 |
Z
zengyawen 已提交
1732

Z
zhangxingxia 已提交
1733
**示例:**
Z
zhangxingxia 已提交
1734
  ```js
Z
zengyawen 已提交
1735 1736 1737 1738 1739 1740 1741 1742
  let stat = fileio.fdatasyncSync(fd);
  ```


## fileio.symlink<sup>7+</sup>

symlink(target: string, srcPath: string): Promise&lt;void&gt;

H
haonan_7 已提交
1743
基于文件路径创建符号链接,使用Promise异步回调。
Z
zengyawen 已提交
1744

1745 1746
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1747
**参数:**
Z
zengyawen 已提交
1748 1749 1750 1751
| 参数名  | 类型   | 必填 | 说明                         |
| ------- | ------ | ---- | ---------------------------- |
| target  | string | 是   | 目标文件的应用沙箱路径。     |
| srcPath | string | 是   | 符号链接文件的应用沙箱路径。 |
Z
zengyawen 已提交
1752

Z
zhangxingxia 已提交
1753
**返回值:**
H
HelloCrease 已提交
1754 1755
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
1756
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
1757

Z
zhangxingxia 已提交
1758
**示例:**
Z
zhangxingxia 已提交
1759
  ```js
W
wangbo 已提交
1760
  fileio.symlink(target, srcPath).then(function() {
H
haonan_7 已提交
1761
      console.info("symlink succeed");
Z
zhangxingxia 已提交
1762 1763
  }).catch(function(err){
      console.info("symlink failed with error:"+ err);
Z
zengyawen 已提交
1764 1765 1766 1767 1768 1769 1770 1771
  });
  ```


## fileio.symlink<sup>7+</sup>

symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
1772
基于文件路径创建符号链接,使用callback异步回调。
Z
zengyawen 已提交
1773

1774 1775
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1776
**参数:**
Z
zengyawen 已提交
1777 1778 1779 1780 1781
| 参数名   | 类型                      | 必填 | 说明                             |
| -------- | ------------------------- | ---- | -------------------------------- |
| target   | string                    | 是   | 目标文件的应用沙箱路径。         |
| srcPath  | string                    | 是   | 符号链接文件的应用沙箱路径。     |
| callback | AsyncCallback&lt;void&gt; | 是   | 异步创建符号链接信息之后的回调。 |
Z
zengyawen 已提交
1782

Z
zhangxingxia 已提交
1783
**示例:**
Z
zhangxingxia 已提交
1784
  ```js
W
wangbo 已提交
1785
  fileio.symlink(target, srcPath, function (err) {
Z
zhangxingxia 已提交
1786
      // do something
Z
zengyawen 已提交
1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
  });
  ```


## fileio.symlinkSync<sup>7+</sup>

symlinkSync(target: string, srcPath: string): void

以同步的方法基于文件路径创建符号链接。

1797 1798
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1799
**参数:**
Z
zengyawen 已提交
1800 1801 1802 1803
| 参数名  | 类型   | 必填 | 说明                         |
| ------- | ------ | ---- | ---------------------------- |
| target  | string | 是   | 目标文件的应用沙箱路径。     |
| srcPath | string | 是   | 符号链接文件的应用沙箱路径。 |
Z
zengyawen 已提交
1804

Z
zhangxingxia 已提交
1805
**示例:**
Z
zhangxingxia 已提交
1806
  ```js
W
wangbo 已提交
1807
  fileio.symlinkSync(target, srcPath);
Z
zengyawen 已提交
1808 1809 1810 1811 1812 1813 1814
  ```


## fileio.chown<sup>7+</sup>

chown(path: string, uid: number, gid: number): Promise&lt;void&gt;

H
haonan_7 已提交
1815
基于文件路径改变文件所有者,使用Promise异步回调。
Z
zengyawen 已提交
1816

1817 1818
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1819
**参数:**
Z
zengyawen 已提交
1820 1821 1822 1823 1824
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待改变文件的应用沙箱路径。 |
| uid    | number | 是   | 新的UID(UserID)。        |
| gid    | number | 是   | 新的GID(GroupID)。       |
Z
zengyawen 已提交
1825

Z
zhangxingxia 已提交
1826
**返回值:**
H
HelloCrease 已提交
1827 1828
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
1829
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
1830

Z
zhangxingxia 已提交
1831
**示例:**
Z
zhangxingxia 已提交
1832
  ```js
Z
zengyawen 已提交
1833
  let stat = fileio.statSync(path);
Z
zengyawen 已提交
1834
  fileio.chown(path, stat.uid, stat.gid).then(function(){
H
haonan_7 已提交
1835
      console.info("chown succeed");
Z
zhangxingxia 已提交
1836 1837 1838
  }).catch(function(err){
      console.info("chown failed with error:"+ err);
  });
Z
zengyawen 已提交
1839 1840 1841 1842 1843 1844 1845
  ```


## fileio.chown<sup>7+</sup>

chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
1846
基于文件路径改变文件所有者,使用callback异步回调。
Z
zengyawen 已提交
1847

1848 1849
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1850
**参数:**
Z
zengyawen 已提交
1851 1852 1853 1854 1855 1856
| 参数名   | 类型                      | 必填 | 说明                           |
| -------- | ------------------------- | ---- | ------------------------------ |
| path     | string                    | 是   | 待改变文件的应用沙箱路径。     |
| uid      | number                    | 是   | 新的UID。                      |
| gid      | number                    | 是   | 新的GID。                      |
| callback | AsyncCallback&lt;void&gt; | 是   | 异步改变文件所有者之后的回调。 |
Z
zengyawen 已提交
1857

Z
zhangxingxia 已提交
1858
**示例:**
Z
zhangxingxia 已提交
1859
  ```js
Z
zhangxingxia 已提交
1860
  let stat = fileio.statSync(path)
Z
zengyawen 已提交
1861
  fileio.chown(path, stat.uid, stat.gid, function (err){
Z
zhangxingxia 已提交
1862
      // do something
Z
zengyawen 已提交
1863 1864 1865 1866 1867 1868 1869 1870 1871 1872
  });
  ```


## fileio.chownSync<sup>7+</sup>

chownSync(path: string, uid: number, gid: number): void

以同步的方法基于文件路径改变文件所有者。

1873 1874
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1875
**参数:**
Z
zengyawen 已提交
1876 1877 1878 1879 1880
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待改变文件的应用沙箱路径。 |
| uid    | number | 是   | 新的UID。                  |
| gid    | number | 是   | 新的GID。                  |
Z
zengyawen 已提交
1881

Z
zhangxingxia 已提交
1882
**示例:**
Z
zhangxingxia 已提交
1883
  ```js
Z
zhangxingxia 已提交
1884
  let stat = fileio.statSync(path)
Z
zengyawen 已提交
1885 1886 1887 1888 1889 1890 1891 1892
  fileio.chownSync(path, stat.uid, stat.gid);
  ```


## fileio.mkdtemp<sup>7+</sup>

mkdtemp(prefix: string): Promise&lt;string&gt;

H
haonan_7 已提交
1893
创建临时目录,使用Promise异步回调。
Z
zengyawen 已提交
1894

1895 1896
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1897
**参数:**
H
HelloCrease 已提交
1898 1899 1900
  | 参数名    | 类型     | 必填   | 说明                          |
  | ------ | ------ | ---- | --------------------------- |
  | prefix | string | 是    | 用随机产生的字符串替换以“XXXXXX”结尾目录路径。 |
Z
zengyawen 已提交
1901

Z
zhangxingxia 已提交
1902
**返回值:**
Z
zhangxingxia 已提交
1903
  | 类型                   | 说明         |
H
HelloCrease 已提交
1904
  | --------------------- | ---------- |
H
haonan_7 已提交
1905
  | Promise&lt;string&gt; | Promise对象。返回生成的唯一目录路径。 |
Z
zengyawen 已提交
1906

Z
zhangxingxia 已提交
1907
**示例:**
Z
zhangxingxia 已提交
1908 1909
  ```js
  fileio.mkdtemp(path + "XXXX").then(function(path){
H
haonan_7 已提交
1910
      console.info("mkdtemp succeed:"+ path);
Z
zhangxingxia 已提交
1911 1912 1913
  }).catch(function(err){
      console.info("mkdtemp failed with error:"+ err);
  });
Z
zengyawen 已提交
1914 1915 1916 1917 1918 1919 1920
  ```


## fileio.mkdtemp<sup>7+</sup>

mkdtemp(prefix: string, callback: AsyncCallback&lt;string&gt;): void

H
haonan_7 已提交
1921
创建临时目录,使用callback异步回调。
Z
zengyawen 已提交
1922

1923 1924
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1925
**参数:**
H
HelloCrease 已提交
1926 1927 1928 1929
  | 参数名      | 类型                          | 必填   | 说明                          |
  | -------- | --------------------------- | ---- | --------------------------- |
  | prefix   | string                      | 是    | 用随机产生的字符串替换以“XXXXXX”结尾目录路径。 |
  | callback | AsyncCallback&lt;string&gt; | 是    | 异步创建临时目录之后的回调。              |
Z
zengyawen 已提交
1930

Z
zhangxingxia 已提交
1931
**示例:**
Z
zhangxingxia 已提交
1932
  ```js
Z
zengyawen 已提交
1933
  fileio.mkdtemp(path + "XXXX", function (err, res) {
Z
zhangxingxia 已提交
1934
      // do something
Z
zengyawen 已提交
1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
  });
  ```


## fileio.mkdtempSync<sup>7+</sup>

mkdtempSync(prefix: string): string

以同步的方法创建临时目录。

1945 1946
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1947
**参数:**
H
HelloCrease 已提交
1948 1949 1950
  | 参数名    | 类型     | 必填   | 说明                          |
  | ------ | ------ | ---- | --------------------------- |
  | prefix | string | 是    | 用随机产生的字符串替换以“XXXXXX”结尾目录路径。 |
Z
zengyawen 已提交
1951

Z
zhangxingxia 已提交
1952
**返回值:**
Z
zhangxingxia 已提交
1953
  | 类型    | 说明         |
H
HelloCrease 已提交
1954
  | ------ | ---------- |
Z
zengyawen 已提交
1955 1956
  | string | 产生的唯一目录路径。 |

Z
zhangxingxia 已提交
1957
**示例:**
Z
zhangxingxia 已提交
1958
  ```js
Z
zengyawen 已提交
1959 1960 1961 1962 1963 1964 1965 1966
  let res = fileio.mkdtempSync(path + "XXXX");
  ```


## fileio.fchmod<sup>7+</sup>

fchmod(fd: number, mode: number): Promise&lt;void&gt;

H
haonan_7 已提交
1967
基于文件描述符改变文件权限,使用Promise异步回调。
Z
zengyawen 已提交
1968

1969 1970
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
1971
**参数:**
H
HelloCrease 已提交
1972 1973 1974 1975
  | 参数名  | 类型     | 必填   | 说明                                       |
  | ---- | ------ | ---- | ---------------------------------------- |
  | fd   | number | 是    | 待改变文件的文件描述符。                             |
  | mode | number | 是    | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
Z
zengyawen 已提交
1976

Z
zhangxingxia 已提交
1977
**返回值:**
Z
zhangxingxia 已提交
1978
  | 类型                 | 说明                           |
H
HelloCrease 已提交
1979
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
1980
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
1981

Z
zhangxingxia 已提交
1982
**示例:**
Z
zhangxingxia 已提交
1983 1984
  ```js
  fileio.fchmod(fd, mode).then(function() {
H
haonan_7 已提交
1985
      console.info("chmod succeed");
Z
zhangxingxia 已提交
1986 1987
  }).catch(function(err){
      console.info("chmod failed with error:"+ err);
Z
zengyawen 已提交
1988 1989 1990 1991 1992 1993 1994 1995
  });
  ```


## fileio.fchmod<sup>7+</sup>

fchmod(fd: number, mode: number, callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
1996
基于文件描述符改变文件权限,使用callback异步回调。
Z
zengyawen 已提交
1997

1998 1999
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2000
**参数:**
H
HelloCrease 已提交
2001 2002 2003 2004 2005
  | 参数名      | 类型                              | 必填   | 说明                                       |
  | -------- | ------------------------------- | ---- | ---------------------------------------- |
  | fd       | number                          | 是    | 待改变文件的文件描述符。                             |
  | mode     | number                          | 是    | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
  | callback | AsyncCallback&nbsp;&lt;void&gt; | 是    | 异步改变文件权限之后的回调。                           |
Z
zengyawen 已提交
2006

Z
zhangxingxia 已提交
2007
**示例:**
Z
zhangxingxia 已提交
2008
  ```js
Z
zengyawen 已提交
2009
  fileio.fchmod(fd, mode, function (err) {
Z
zhangxingxia 已提交
2010
      // do something
Z
zengyawen 已提交
2011 2012 2013 2014 2015 2016
  });
  ```


## fileio.fchmodSync<sup>7+</sup>

2017
fchmodSync(fd: number, mode: number): void
Z
zengyawen 已提交
2018 2019 2020

以同步方法基于文件描述符改变文件权限。

2021 2022
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2023
**参数:**
H
HelloCrease 已提交
2024 2025 2026 2027
  | 参数名  | 类型     | 必填   | 说明                                       |
  | ---- | ------ | ---- | ---------------------------------------- |
  | fd   | number | 是    | 待改变文件的文件描述符。                             |
  | mode | number | 是    | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限。<br/>-&nbsp;0o700:所有者具有读、写及可执行权限。<br/>-&nbsp;0o400:所有者具有读权限。<br/>-&nbsp;0o200:所有者具有写权限。<br/>-&nbsp;0o100:所有者具有可执行权限。<br/>-&nbsp;0o070:所有用户组具有读、写及可执行权限。<br/>-&nbsp;0o040:所有用户组具有读权限。<br/>-&nbsp;0o020:所有用户组具有写权限。<br/>-&nbsp;0o010:所有用户组具有可执行权限。<br/>-&nbsp;0o007:其余用户具有读、写及可执行权限。<br/>-&nbsp;0o004:其余用户具有读权限。<br/>-&nbsp;0o002:其余用户具有写权限。<br/>-&nbsp;0o001:其余用户具有可执行权限。 |
Z
zengyawen 已提交
2028

Z
zhangxingxia 已提交
2029
**示例:**
Z
zhangxingxia 已提交
2030
  ```js
W
wangbo 已提交
2031
   fileio.fchmodSync(fd, mode);
Z
zengyawen 已提交
2032 2033 2034 2035 2036 2037 2038
  ```


## fileio.createStream<sup>7+</sup>

createStream(path: string, mode: string): Promise&lt;Stream&gt;

H
haonan_7 已提交
2039
基于文件路径打开文件流,使用Promise异步回调。
Z
zengyawen 已提交
2040

2041 2042
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2043
**参数:**
Z
zengyawen 已提交
2044 2045 2046 2047
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path   | string | 是   | 待打开文件的应用沙箱路径。                                   |
| mode   | string | 是   | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
Z
zengyawen 已提交
2048

Z
zhangxingxia 已提交
2049
**返回值:**
H
HelloCrease 已提交
2050 2051
  | 类型                                | 说明        |
  | --------------------------------- | --------- |
H
haonan_7 已提交
2052
  | Promise&lt;[Stream](#stream7)&gt; | Promise对象。返回文件流的结果。 |
Z
zengyawen 已提交
2053

Z
zhangxingxia 已提交
2054
**示例:**
Z
zhangxingxia 已提交
2055 2056
  ```js
  fileio.createStream(path, "r+").then(function(stream){
H
haonan_7 已提交
2057
      console.info("createStream succeed");
Z
zhangxingxia 已提交
2058 2059 2060
  }).catch(function(err){
      console.info("createStream failed with error:"+ err);
  });
Z
zengyawen 已提交
2061 2062 2063 2064 2065 2066 2067
  ```


## fileio.createStream<sup>7+</sup>

createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): void

H
haonan_7 已提交
2068
基于文件路径打开文件流,使用callback异步回调。
Z
zengyawen 已提交
2069

2070 2071
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2072
**参数:**
Z
zengyawen 已提交
2073 2074 2075 2076 2077
| 参数名   | 类型                                    | 必填 | 说明                                                         |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| path     | string                                  | 是   | 待打开文件的应用沙箱路径。                                   |
| mode     | string                                  | 是   | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
| callback | AsyncCallback&lt;[Stream](#stream7)&gt; | 是   | 异步打开文件流之后的回调。                                   |
Z
zengyawen 已提交
2078

Z
zhangxingxia 已提交
2079
**示例:**
Z
zhangxingxia 已提交
2080
  ```js
Z
zhangxingxia 已提交
2081
  fileio.createStream(path, "r+", function(err, stream){
Z
zhangxingxia 已提交
2082
      // do something
Z
zengyawen 已提交
2083 2084 2085 2086 2087 2088 2089 2090 2091 2092
  });
  ```


## fileio.createStreamSync<sup>7+</sup>

createStreamSync(path: string, mode: string): Stream

以同步方法基于文件路径打开文件流。

2093 2094
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2095
**参数:**
Z
zengyawen 已提交
2096 2097 2098 2099
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path   | string | 是   | 待打开文件的应用沙箱路径。                                   |
| mode   | string | 是   | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
Z
zengyawen 已提交
2100

Z
zhangxingxia 已提交
2101
**返回值:**
Z
zhangxingxia 已提交
2102
  | 类型                | 说明        |
H
HelloCrease 已提交
2103
  | ------------------ | --------- |
Z
zengyawen 已提交
2104 2105
  | [Stream](#stream7) | 返回文件流的结果。 |

Z
zhangxingxia 已提交
2106
**示例:**
Z
zhangxingxia 已提交
2107
  ```js
Z
zengyawen 已提交
2108 2109 2110 2111 2112 2113 2114 2115
  let ss = fileio.createStreamSync(path, "r+");
  ```


## fileio.fdopenStream<sup>7+</sup>

fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;

H
haonan_7 已提交
2116
基于文件描述符打开文件流,使用Promise异步回调。
Z
zengyawen 已提交
2117

2118 2119
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2120
**参数:**
H
HelloCrease 已提交
2121 2122 2123 2124
  | 参数名  | 类型     | 必填   | 说明                                       |
  | ---- | ------ | ---- | ---------------------------------------- |
  | fd   | number | 是    | 待打开文件的文件描述符。                             |
  | mode | string | 是    | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
Z
zengyawen 已提交
2125

Z
zhangxingxia 已提交
2126
**返回值:**
Z
zhangxingxia 已提交
2127
  | 类型                               | 说明        |
H
HelloCrease 已提交
2128
  | --------------------------------- | --------- |
H
haonan_7 已提交
2129
  | Promise&lt;[Stream](#stream7)&gt; | Promise对象。返回文件流的结果。 |
Z
zengyawen 已提交
2130

Z
zhangxingxia 已提交
2131
**示例:**
Z
zhangxingxia 已提交
2132
  ```js
Z
zhangxingxia 已提交
2133 2134
  let fd = fileio.openSync(path);
  fileio.fdopenStream(fd, "r+").then(function(stream){
H
haonan_7 已提交
2135
      console.info("openStream succeed");
Z
zhangxingxia 已提交
2136 2137 2138
  }).catch(function(err){
      console.info("openStream failed with error:"+ err);
  });
Z
zengyawen 已提交
2139 2140 2141 2142 2143 2144 2145
  ```


## fileio.fdopenStream<sup>7+</sup>

fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): void

H
haonan_7 已提交
2146
基于文件描述符打开文件流,使用callback异步回调。
Z
zengyawen 已提交
2147

2148 2149
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2150
**参数:**
H
HelloCrease 已提交
2151 2152 2153 2154 2155
  | 参数名      | 类型                                       | 必填   | 说明                                       |
  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
  | fd       | number                                   | 是    | 待打开文件的文件描述符。                             |
  | mode     | string                                   | 是    | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
  | callback | AsyncCallback&nbsp;&lt;[Stream](#stream7)&gt; | 是    | 异步打开文件流之后的回调。                            |
Z
zengyawen 已提交
2156

Z
zhangxingxia 已提交
2157
**示例:**
Z
zhangxingxia 已提交
2158
  ```js
Z
zhangxingxia 已提交
2159 2160
  let fd = fileio.openSync(path);
  fileio.fdopenStream(fd, "r+", function (err, stream) {
Z
zhangxingxia 已提交
2161
      // do something
Z
zengyawen 已提交
2162 2163 2164 2165 2166 2167 2168 2169 2170 2171
  });
  ```


## fileio.fdopenStreamSync<sup>7+</sup>

fdopenStreamSync(fd: number, mode: string): Stream

以同步方法基于文件描述符打开文件流。

2172 2173
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2174
**参数:**
H
HelloCrease 已提交
2175 2176 2177 2178
  | 参数名  | 类型     | 必填   | 说明                                       |
  | ---- | ------ | ---- | ---------------------------------------- |
  | fd   | number | 是    | 待打开文件的文件描述符。                             |
  | mode | string | 是    | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
Z
zengyawen 已提交
2179

Z
zhangxingxia 已提交
2180
**返回值:**
Z
zhangxingxia 已提交
2181
  | 类型                | 说明        |
H
HelloCrease 已提交
2182
  | ------------------ | --------- |
Z
zengyawen 已提交
2183 2184
  | [Stream](#stream7) | 返回文件流的结果。 |

Z
zhangxingxia 已提交
2185
**示例:**
Z
zhangxingxia 已提交
2186
  ```js
Z
zhangxingxia 已提交
2187
  let fd = fileio.openSync(path);
Z
zengyawen 已提交
2188 2189 2190 2191 2192 2193 2194 2195
  let ss = fileio.fdopenStreamSync(fd, "r+");
  ```


## fileio.fchown<sup>7+</sup>

fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt;

H
haonan_7 已提交
2196
基于文件描述符改变文件所有者,使用Promise异步回调。
Z
zengyawen 已提交
2197

2198 2199
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2200
**参数:**
H
HelloCrease 已提交
2201 2202 2203 2204 2205
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
  | fd   | number | 是    | 待改变文件的文件描述符。 |
  | uid  | number | 是    | 文件所有者的UID。   |
  | gid  | number | 是    | 文件所有组的GID。   |
Z
zengyawen 已提交
2206

Z
zhangxingxia 已提交
2207
**返回值:**
H
HelloCrease 已提交
2208 2209
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
2210
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
2211

Z
zhangxingxia 已提交
2212
**示例:**
Z
zhangxingxia 已提交
2213
  ```js
Z
zengyawen 已提交
2214
  let stat = fileio.statSync(path);
Z
zhangxingxia 已提交
2215
  fileio.fchown(fd, stat.uid, stat.gid).then(function() {
H
haonan_7 已提交
2216
      console.info("chown succeed");
Z
zhangxingxia 已提交
2217 2218
  }).catch(function(err){
      console.info("chown failed with error:"+ err);
Z
zengyawen 已提交
2219 2220 2221 2222 2223 2224 2225 2226
  });
  ```


## fileio.fchown<sup>7+</sup>

fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
2227
基于文件描述符改变文件所有者,使用callback异步回调。
Z
zengyawen 已提交
2228

2229 2230
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2231
**参数:**
H
HelloCrease 已提交
2232 2233 2234 2235 2236 2237
  | 参数名      | 类型                        | 必填   | 说明              |
  | -------- | ------------------------- | ---- | --------------- |
  | fd       | number                    | 是    | 待改变文件的文件描述符。    |
  | uid      | number                    | 是    | 文件所有者的UID。      |
  | gid      | number                    | 是    | 文件所有组的GID。      |
  | callback | AsyncCallback&lt;void&gt; | 是    | 异步改变文件所有者之后的回调。 |
Z
zengyawen 已提交
2238

Z
zhangxingxia 已提交
2239
**示例:**
Z
zhangxingxia 已提交
2240
  ```js
Z
zhangxingxia 已提交
2241
  let stat = fileio.statSync(path);
Z
zengyawen 已提交
2242
  fileio.fchown(fd, stat.uid, stat.gid, function (err){
Z
zhangxingxia 已提交
2243
      // do something
Z
zengyawen 已提交
2244 2245 2246 2247 2248 2249 2250 2251 2252 2253
  });
  ```


## fileio.fchownSync<sup>7+</sup>

fchownSync(fd: number, uid: number, gid: number): void

以同步方法基于文件描述符改变文件所有者。

2254 2255
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2256
**参数:**
H
HelloCrease 已提交
2257 2258 2259 2260 2261
  | 参数名  | 类型     | 必填   | 说明           |
  | ---- | ------ | ---- | ------------ |
  | fd   | number | 是    | 待改变文件的文件描述符。 |
  | uid  | number | 是    | 文件所有者的UID。   |
  | gid  | number | 是    | 文件所有组的GID。   |
Z
zengyawen 已提交
2262

Z
zhangxingxia 已提交
2263
**示例:**
Z
zhangxingxia 已提交
2264
  ```js
Z
zhangxingxia 已提交
2265
  let stat = fileio.statSync(path);
Z
zengyawen 已提交
2266 2267 2268 2269 2270 2271 2272 2273
  fileio.fchownSync(fd, stat.uid, stat.gid);
  ```


## fileio.lchown<sup>7+</sup>

lchown(path: string, uid: number, gid: number): Promise&lt;void&gt;

H
haonan_7 已提交
2274
基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是符号链接所指向的实际文件,使用Promise异步回调。
Z
zengyawen 已提交
2275

2276 2277
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2278
**参数:**
Z
zengyawen 已提交
2279 2280 2281 2282 2283
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待打开文件的应用沙箱路径。 |
| uid    | number | 是   | 新的UID。                  |
| gid    | number | 是   | 新的GID。                  |
Z
zengyawen 已提交
2284

Z
zhangxingxia 已提交
2285
**返回值:**
H
HelloCrease 已提交
2286 2287
  | 类型                  | 说明                           |
  | ------------------- | ---------------------------- |
H
haonan_7 已提交
2288
  | Promise&lt;void&gt; | Promise对象。无返回值。 |
Z
zengyawen 已提交
2289

Z
zhangxingxia 已提交
2290
**示例:**
Z
zhangxingxia 已提交
2291
  ```js
Z
zengyawen 已提交
2292
  let stat = fileio.statSync(path);
Z
zhangxingxia 已提交
2293
  fileio.lchown(path, stat.uid, stat.gid).then(function() {
H
haonan_7 已提交
2294
      console.info("chown succeed");
Z
zhangxingxia 已提交
2295 2296 2297
  }).catch(function(err){
      console.info("chown failed with error:"+ err);
  });
Z
zengyawen 已提交
2298 2299 2300 2301 2302 2303 2304
  ```


## fileio.lchown<sup>7+</sup>

lchown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
2305
基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是更改符号链接所指向的实际文件,使用callback异步回调。
Z
zengyawen 已提交
2306

2307 2308
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2309
**参数:**
Z
zengyawen 已提交
2310 2311 2312 2313 2314 2315
| 参数名   | 类型                      | 必填 | 说明                           |
| -------- | ------------------------- | ---- | ------------------------------ |
| path     | string                    | 是   | 待打开文件的应用沙箱路径。     |
| uid      | number                    | 是   | 新的UID。                      |
| gid      | number                    | 是   | 新的GID。                      |
| callback | AsyncCallback&lt;void&gt; | 是   | 异步改变文件所有者之后的回调。 |
Z
zengyawen 已提交
2316

Z
zhangxingxia 已提交
2317
**示例:**
Z
zhangxingxia 已提交
2318
  ```js
Z
zengyawen 已提交
2319 2320
  let stat = fileio.statSync(path);
  fileio.lchown(path, stat.uid, stat.gid, function (err){
Z
zhangxingxia 已提交
2321
      // do something
Z
zengyawen 已提交
2322 2323 2324 2325 2326 2327 2328 2329 2330 2331
  });
  ```


## fileio.lchownSync<sup>7+</sup>

lchownSync(path: string, uid: number, gid: number): void

以同步方法基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是更改符号链接所指向的实际文件。

2332 2333
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2334
**参数:**
Z
zengyawen 已提交
2335 2336 2337 2338 2339
| 参数名 | 类型   | 必填 | 说明                       |
| ------ | ------ | ---- | -------------------------- |
| path   | string | 是   | 待打开文件的应用沙箱路径。 |
| uid    | number | 是   | 新的UID。                  |
| gid    | number | 是   | 新的GID。                  |
Z
zengyawen 已提交
2340

Z
zhangxingxia 已提交
2341
**示例:**
Z
zhangxingxia 已提交
2342
  ```js
Z
zengyawen 已提交
2343 2344 2345 2346 2347 2348 2349 2350 2351
  let stat = fileio.statSync(path);
  fileio.lchownSync(path, stat.uid, stat.gid);
  ```


## fileio.createWatcher<sup>7+</sup>

createWatcher(filename: string, events: number, callback: AsyncCallback&lt;number&gt;): Watcher

H
haonan_7 已提交
2352
监听文件或者目录的变化,使用callback异步回调。
Z
zengyawen 已提交
2353

2354 2355
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2356
**参数:**
Z
zengyawen 已提交
2357 2358 2359 2360 2361
| 参数名   | 类型                              | 必填 | 说明                                                         |
| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
| filename | string                            | 是   | 待监视文件的应用沙箱路径。                                   |
| events   | Number                            | 是   | -&nbsp;1:&nbsp;监听文件或者目录是否发生重命名。<br/>-&nbsp;2:监听文件或者目录内容的是否修改。<br/>-&nbsp;3:两者都有。 |
| callback | AsyncCallback&lt;number&nbsp;&gt; | 是   | 每发生变化一次,调用一次此函数。                             |
Z
zengyawen 已提交
2362

Z
zhangxingxia 已提交
2363
**返回值:**
Z
zhangxingxia 已提交
2364
  | 类型                  | 说明         |
H
HelloCrease 已提交
2365
  | -------------------- | ---------- |
H
haonan_7 已提交
2366
  | [Watcher](#watcher7) | Promise对象。返回文件变化监听的实例。 |
Z
zengyawen 已提交
2367

Z
zhangxingxia 已提交
2368
**示例:**
Z
zhangxingxia 已提交
2369
  ```js
Z
zhangxingxia 已提交
2370 2371
  let filename = path +"/test.txt";
  fileio.createWatcher(filename, 1, function(number){
Z
zhangxingxia 已提交
2372
     console.info("Monitoring times: "+number);
Z
zengyawen 已提交
2373
  });
Z
zhangxingxia 已提交
2374
  
Z
zengyawen 已提交
2375 2376 2377 2378 2379 2380 2381
  ```


## Readout

仅用于read方法,获取文件的读取结果。

2382 2383
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.File.FileIO。

H
HelloCrease 已提交
2384 2385 2386 2387 2388
| 名称        | 参数类型       | 可读   | 可写   | 说明                |
| --------- | ---------- | ---- | ---- | ----------------- |
| bytesRead | number     | 是    | 是    | 实际读取长度。           |
| offset    | number     | 是    | 是    | 读取数据相对于缓冲区首地址的偏移。 |
| buffer    | ArrayBufer | 是    | 是    | 保存读取数据的缓冲区。       |
Z
zengyawen 已提交
2389 2390 2391 2392 2393


## Stat

文件具体信息,在调用Stat的方法前,需要先通过[stat()](#fileiostat)方法(同步或异步)来构建一个Stat实例。
Z
zengyawen 已提交
2394

2395
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.File.FileIO。
Z
zengyawen 已提交
2396

Z
zengyawen 已提交
2397
### 属性
Z
zengyawen 已提交
2398

H
HelloCrease 已提交
2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412
| 名称     | 参数类型   | 可读   | 可写   | 说明                                       |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
| dev    | number | 是    | 否    | 标识包含该文件的主设备号。                            |
| ino    | number | 是    | 否    | 标识该文件。通常同设备上的不同文件的INO不同。                 |
| mode   | number | 是    | 否    | 表示文件类型及权限,其首&nbsp;4&nbsp;位表示文件类型,后&nbsp;12&nbsp;位表示权限。各特征位的含义如下:<br/>-&nbsp;0o170000:可用于获取文件类型的掩码。<br/>-&nbsp;0o140000:文件是套接字。<br/>-&nbsp;0o120000:文件是符号链接。<br/>-&nbsp;0o100000:文件是一般文件。<br/>-&nbsp;0o060000:文件属于块设备。<br/>-&nbsp;0o040000:文件是目录。<br/>-&nbsp;0o020000:文件是字符设备。<br/>-&nbsp;0o010000:文件是具名管道,即FIFO。<br/>-&nbsp;0o0700:可用于获取用户权限的掩码。<br/>-&nbsp;0o0400:用户读,对于普通文件,所有者可读取文件;对于目录,所有者可读取目录项。<br/>-&nbsp;0o0200:用户写,对于普通文件,所有者可写入文件;对于目录,所有者可创建/删除目录项。<br/>-&nbsp;0o0100:用户执行,对于普通文件,所有者可执行文件;对于目录,所有者可在目录中搜索给定路径名。<br/>-&nbsp;0o0070:可用于获取用户组权限的掩码。<br/>-&nbsp;0o0040:用户组读,对于普通文件,所有用户组可读取文件;对于目录,所有用户组可读取目录项。<br/>-&nbsp;0o0020:用户组写,对于普通文件,所有用户组可写入文件;对于目录,所有用户组可创建/删除目录项。<br/>-&nbsp;0o0010:用户组执行,对于普通文件,所有用户组可执行文件;对于目录,所有用户组是否可在目录中搜索给定路径名。<br/>-&nbsp;0o0007:可用于获取其他用户权限的掩码。<br/>-&nbsp;0o0004:其他读,对于普通文件,其余用户可读取文件;对于目录,其他用户组可读取目录项。<br/>-&nbsp;0o0002:其他写,对于普通文件,其余用户可写入文件;对于目录,其他用户组可创建/删除目录项。<br/>-&nbsp;0o0001:其他执行,对于普通文件,其余用户可执行文件;对于目录,其他用户组可在目录中搜索给定路径名。 |
| nlink  | number | 是    | 否    | 文件的硬链接数。                                 |
| uid    | number | 是    | 否    | 文件所有者的ID。                                |
| gid    | number | 是    | 否    | 文件所有组的ID。                                |
| rdev   | number | 是    | 否    | 标识包含该文件的从设备号。                            |
| size   | number | 是    | 否    | 文件的大小,以字节为单位。仅对普通文件有效。                   |
| blocks | number | 是    | 否    | 文件占用的块数,计算时块大小按512B计算。                   |
| atime  | number | 是    | 否    | 上次访问该文件的时间,表示距1970年1月1日0时0分0秒的秒数。        |
| mtime  | number | 是    | 否    | 上次修改该文件的时间,表示距1970年1月1日0时0分0秒的秒数。        |
| ctime  | number | 是    | 否    | 最近改变文件状态的时间,表示距1970年1月1日0时0分0秒的秒数。       |
Z
zengyawen 已提交
2413 2414


Z
zengyawen 已提交
2415
### isBlockDevice
Z
zengyawen 已提交
2416

Z
zengyawen 已提交
2417
isBlockDevice(): boolean
Z
zengyawen 已提交
2418

Z
zhangxingxia 已提交
2419
用于判断文件是否是块特殊文件。一个块特殊文件只能以块为粒度进行访问,且访问的时候带缓存。
Z
zengyawen 已提交
2420

2421 2422
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2423
**返回值:**
H
HelloCrease 已提交
2424 2425
  | 类型      | 说明               |
  | ------- | ---------------- |
Z
zhangxingxia 已提交
2426
  | boolean | 表示文件是否是块特殊设备。 |
Z
zengyawen 已提交
2427

Z
zhangxingxia 已提交
2428
**示例:**
Z
zhangxingxia 已提交
2429
  ```js
Z
zengyawen 已提交
2430 2431
  let isBLockDevice = fileio.statSync(path).isBlockDevice();
  ```
Z
zengyawen 已提交
2432 2433


Z
zengyawen 已提交
2434
### isCharacterDevice
Z
zengyawen 已提交
2435

Z
zengyawen 已提交
2436
isCharacterDevice(): boolean
Z
zengyawen 已提交
2437

Z
zhangxingxia 已提交
2438
用于判断文件是否是字符特殊文件。一个字符特殊设备可进行随机访问,且访问的时候不带缓存。
Z
zengyawen 已提交
2439

2440 2441
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2442
**返回值:**
H
HelloCrease 已提交
2443 2444
  | 类型      | 说明                |
  | ------- | ----------------- |
Z
zhangxingxia 已提交
2445
  | boolean | 表示文件是否是字符特殊设备。 |
Z
zengyawen 已提交
2446

Z
zhangxingxia 已提交
2447
**示例:**
Z
zhangxingxia 已提交
2448
  ```js
Z
zengyawen 已提交
2449 2450
  let isCharacterDevice = fileio.statSync(path).isCharacterDevice();
  ```
Z
zengyawen 已提交
2451 2452


Z
zengyawen 已提交
2453
### isDirectory
Z
zengyawen 已提交
2454

Z
zengyawen 已提交
2455
isDirectory(): boolean
Z
zengyawen 已提交
2456

Z
zhangxingxia 已提交
2457
用于判断文件是否是目录。
Z
zengyawen 已提交
2458

2459 2460
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2461
**返回值:**
H
HelloCrease 已提交
2462 2463
  | 类型      | 说明            |
  | ------- | ------------- |
Z
zhangxingxia 已提交
2464
  | boolean | 表示文件是否是目录。 |
Z
zengyawen 已提交
2465

Z
zhangxingxia 已提交
2466
**示例:**
Z
zhangxingxia 已提交
2467
  ```js
Z
zengyawen 已提交
2468
  let isDirectory = fileio.statSync(path).isDirectory(); 
Z
zengyawen 已提交
2469
  ```
Z
zengyawen 已提交
2470 2471


Z
zengyawen 已提交
2472
### isFIFO
Z
zengyawen 已提交
2473

Z
zengyawen 已提交
2474
isFIFO(): boolean
Z
zengyawen 已提交
2475

Z
zhangxingxia 已提交
2476
用于判断文件是否是命名管道(有时也称为FIFO)。命名管道通常用于进程间通信。
Z
zengyawen 已提交
2477

2478 2479
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2480
**返回值:**
H
HelloCrease 已提交
2481 2482
  | 类型      | 说明                    |
  | ------- | --------------------- |
Z
zhangxingxia 已提交
2483
  | boolean | 表示文件是否是&nbsp;FIFO。 |
Z
zengyawen 已提交
2484

Z
zhangxingxia 已提交
2485
**示例:**
Z
zhangxingxia 已提交
2486
  ```js
Z
zengyawen 已提交
2487
  let isFIFO = fileio.statSync(path).isFIFO(); 
Z
zengyawen 已提交
2488
  ```
Z
zengyawen 已提交
2489 2490


Z
zengyawen 已提交
2491
### isFile
Z
zengyawen 已提交
2492

Z
zengyawen 已提交
2493
isFile(): boolean
Z
zengyawen 已提交
2494

Z
zhangxingxia 已提交
2495
用于判断文件是否是普通文件。
Z
zengyawen 已提交
2496

2497 2498
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2499
**返回值:**
H
HelloCrease 已提交
2500 2501
  | 类型      | 说明              |
  | ------- | --------------- |
Z
zhangxingxia 已提交
2502
  | boolean | 表示文件是否是普通文件。 |
Z
zengyawen 已提交
2503

Z
zhangxingxia 已提交
2504
**示例:**
Z
zhangxingxia 已提交
2505
  ```js
Z
zhangxingxia 已提交
2506
  let isFile = fileio.statSync(path).isFile();
Z
zengyawen 已提交
2507
  ```
Z
zengyawen 已提交
2508 2509


Z
zengyawen 已提交
2510
### isSocket
Z
zengyawen 已提交
2511

Z
zengyawen 已提交
2512
isSocket(): boolean
Z
zengyawen 已提交
2513

Z
zhangxingxia 已提交
2514
用于判断文件是否是套接字。
Z
zengyawen 已提交
2515

2516 2517
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2518
**返回值:**
H
HelloCrease 已提交
2519 2520
  | 类型      | 说明             |
  | ------- | -------------- |
Z
zhangxingxia 已提交
2521
  | boolean | 表示文件是否是套接字。 |
Z
zengyawen 已提交
2522

Z
zhangxingxia 已提交
2523
**示例:**
Z
zhangxingxia 已提交
2524
  ```js
Z
zengyawen 已提交
2525 2526
  let isSocket = fileio.statSync(path).isSocket(); 
  ```
Z
zengyawen 已提交
2527 2528


Z
zengyawen 已提交
2529
### isSymbolicLink
Z
zengyawen 已提交
2530

Z
zengyawen 已提交
2531
isSymbolicLink(): boolean
Z
zengyawen 已提交
2532

Z
zhangxingxia 已提交
2533
用于判断文件是否是符号链接。
Z
zengyawen 已提交
2534

2535 2536
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2537
**返回值:**
H
HelloCrease 已提交
2538 2539
  | 类型      | 说明              |
  | ------- | --------------- |
Z
zhangxingxia 已提交
2540
  | boolean | 表示文件是否是符号链接。 |
Z
zengyawen 已提交
2541

Z
zhangxingxia 已提交
2542
**示例:**
Z
zhangxingxia 已提交
2543
  ```js
Z
zengyawen 已提交
2544 2545
  let isSymbolicLink = fileio.statSync(path).isSymbolicLink(); 
  ```
Z
zengyawen 已提交
2546 2547


Z
zengyawen 已提交
2548 2549 2550 2551 2552 2553 2554
## Watcher<sup>7+</sup>

Watcher是文件变化监听的实例,调用Watcher.stop()方法(同步或异步)来停止文件监听。


### stop<sup>7+</sup>

2555
stop(): Promise&lt;void&gt;
Z
zengyawen 已提交
2556

H
haonan_7 已提交
2557
关闭watcher监听,使用Promise异步回调。
Z
zengyawen 已提交
2558

2559 2560
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2561
**示例:**
Z
zhangxingxia 已提交
2562
  ```js
Z
zhangxingxia 已提交
2563
  let filename = path +"/test.txt";
Z
zhangxingxia 已提交
2564
  let watcher = await fileio.createWatcher(filename, 1, function(number){
Z
zhangxingxia 已提交
2565
      console.info("Monitoring times: "+number);
Z
zhangxingxia 已提交
2566 2567
  });
  watcher.stop().then(function(){
Z
zhangxingxia 已提交
2568
       console.info("close watcher succeed");
Z
zhangxingxia 已提交
2569
  });
Z
zengyawen 已提交
2570 2571 2572 2573 2574
  ```


### stop<sup>7+</sup>

2575
stop(callback: AsyncCallback&lt;void&gt;): void
Z
zengyawen 已提交
2576

H
haonan_7 已提交
2577
关闭watcher监听,使用callback异步回调。
Z
zengyawen 已提交
2578

2579 2580
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2581
**参数:**
H
HelloCrease 已提交
2582 2583 2584
  | 参数名      | 类型                        | 必填   | 说明                     |
  | -------- | ------------------------- | ---- | ---------------------- |
  | callback | AsyncCallback&lt;void&gt; | 是    | 以异步方法关闭watcher监听之后的回调。 |
Z
zengyawen 已提交
2585

Z
zhangxingxia 已提交
2586
**示例:**
Z
zhangxingxia 已提交
2587
  ```js
Z
zhangxingxia 已提交
2588
  let filename = path +"/test.txt";
Z
zhangxingxia 已提交
2589
  let watcher = await fileio.createWatcher(filename, 1, function(number){
Z
zhangxingxia 已提交
2590
      console.info("Monitoring times: "+number);
Z
zengyawen 已提交
2591
  });
Z
zhangxingxia 已提交
2592 2593 2594
  watcher.stop(function(){
      console.info("close watcher succeed");
  })
Z
zengyawen 已提交
2595 2596 2597
  ```


Z
zhangxingxia 已提交
2598
## Stream
Z
zengyawen 已提交
2599

Z
zengyawen 已提交
2600 2601 2602 2603 2604 2605 2606
文件流,在调用Stream的方法前,需要先通过createStream()方法(同步或异步)来构建一个Stream实例。


### close<sup>7+</sup>

close(): Promise&lt;void&gt;

H
haonan_7 已提交
2607
关闭文件流,使用Promise异步回调。
Z
zengyawen 已提交
2608

2609 2610
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2611
**返回值:**
H
HelloCrease 已提交
2612 2613
  | 类型                  | 说明            |
  | ------------------- | ------------- |
H
haonan_7 已提交
2614
  | Promise&lt;void&gt; | Promise对象。返回表示异步关闭文件流的结果。 |
Z
zengyawen 已提交
2615

Z
zhangxingxia 已提交
2616
**示例:**
Z
zhangxingxia 已提交
2617
  ```js
Z
zhangxingxia 已提交
2618
  let ss= fileio.createStreamSync(path, "r+");
Z
zhangxingxia 已提交
2619
  ss.close().then(function(){
H
haonan_7 已提交
2620
      console.info("close fileStream succeed");
Z
zhangxingxia 已提交
2621 2622 2623
  }).catch(function(err){
      console.info("close fileStream  failed with error:"+ err);
  });
Z
zengyawen 已提交
2624 2625 2626 2627 2628 2629 2630
  ```


### close<sup>7+</sup>

close(callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
2631
异步关闭文件流,使用callback异步回调。
Z
zengyawen 已提交
2632

2633 2634
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2635
**参数:**
H
HelloCrease 已提交
2636 2637 2638
  | 参数名      | 类型                        | 必填   | 说明            |
  | -------- | ------------------------- | ---- | ------------- |
  | callback | AsyncCallback&lt;void&gt; | 是    | 异步关闭文件流之后的回调。 |
Z
zengyawen 已提交
2639

Z
zhangxingxia 已提交
2640
**示例:**
Z
zhangxingxia 已提交
2641
  ```js
Z
zhangxingxia 已提交
2642
  let ss= fileio.createStreamSync(path, "r+");
Z
zengyawen 已提交
2643
  ss.close(function (err) {
Z
zhangxingxia 已提交
2644
      // do something
Z
zengyawen 已提交
2645 2646
  });
  ```
Z
zengyawen 已提交
2647 2648


2649
### closeSync
Z
zengyawen 已提交
2650

Z
zengyawen 已提交
2651
closeSync(): void
Z
zengyawen 已提交
2652

Z
zengyawen 已提交
2653
同步关闭文件流。
Z
zengyawen 已提交
2654

2655 2656
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2657
**示例:**
Z
zhangxingxia 已提交
2658
  ```js
Z
zhangxingxia 已提交
2659
  let ss= fileio.createStreamSync(path, "r+");
Z
zengyawen 已提交
2660 2661
  ss.closeSync();
  ```
Z
zengyawen 已提交
2662 2663


Z
zengyawen 已提交
2664 2665 2666 2667
### flush<sup>7+</sup>

flush(): Promise&lt;void&gt;

H
haonan_7 已提交
2668
刷新文件流,使用Promise异步回调。
Z
zengyawen 已提交
2669

2670 2671
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2672
**返回值:**
H
HelloCrease 已提交
2673 2674
  | 类型                  | 说明            |
  | ------------------- | ------------- |
H
haonan_7 已提交
2675
  | Promise&lt;void&gt; | Promise对象。返回表示异步刷新文件流的结果。 |
Z
zengyawen 已提交
2676

Z
zhangxingxia 已提交
2677
**示例:**
Z
zhangxingxia 已提交
2678
  ```js
Z
zhangxingxia 已提交
2679
  let ss= fileio.createStreamSync(path, "r+");
Z
zhangxingxia 已提交
2680
  ss.flush().then(function (){
H
haonan_7 已提交
2681
      console.info("flush succeed");
Z
zhangxingxia 已提交
2682 2683 2684
  }).catch(function(err){
      console.info("flush failed with error:"+ err);
  });
Z
zengyawen 已提交
2685 2686 2687 2688 2689 2690 2691
  ```


### flush<sup>7+</sup>

flush(callback: AsyncCallback&lt;void&gt;): void

H
haonan_7 已提交
2692
异步刷新文件流,使用callback异步回调。
Z
zengyawen 已提交
2693

2694 2695
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2696
**参数:**
H
HelloCrease 已提交
2697 2698 2699
  | 参数名      | 类型                        | 必填   | 说明             |
  | -------- | ------------------------- | ---- | -------------- |
  | callback | AsyncCallback&lt;void&gt; | 是    | 异步刷新文件流后的回调函数。 |
Z
zengyawen 已提交
2700

Z
zhangxingxia 已提交
2701
**示例:**
Z
zhangxingxia 已提交
2702
  ```js
Z
zhangxingxia 已提交
2703
  let ss= fileio.createStreamSync(path, "r+");
Z
zengyawen 已提交
2704
  ss.flush(function (err) {
Z
zhangxingxia 已提交
2705
      // do something
Z
zengyawen 已提交
2706 2707 2708 2709
  });
  ```


Z
zengyawen 已提交
2710
### flushSync<sup>7+</sup>
Z
zengyawen 已提交
2711

Z
zengyawen 已提交
2712
flushSync(): void
Z
zengyawen 已提交
2713

Z
zengyawen 已提交
2714
同步刷新文件流。
Z
zengyawen 已提交
2715

2716 2717
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2718
**示例:**
Z
zhangxingxia 已提交
2719
  ```js
Z
zhangxingxia 已提交
2720
  let ss= fileio.createStreamSync(path, "r+");
Z
zengyawen 已提交
2721 2722
  ss.flushSync();
  ```
Z
zengyawen 已提交
2723 2724


Z
zengyawen 已提交
2725 2726
### write<sup>7+</sup>

2727 2728 2729 2730 2731 2732
write(buffer: ArrayBuffer | string, options?: {
    offset?: number;
    length?: number;
    position?: number;
    encoding?: string;
}): Promise&lt;number&gt;
Z
zengyawen 已提交
2733

H
haonan_7 已提交
2734
将数据写入流文件,使用Promise异步回调。
Z
zengyawen 已提交
2735

2736 2737
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2738
**参数:**
H
HelloCrease 已提交
2739 2740 2741
  | 参数名     | 类型                              | 必填   | 说明                                       |
  | ------- | ------------------------------- | ---- | ---------------------------------------- |
  | buffer  | ArrayBuffer&nbsp;\|&nbsp;string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
Z
zhangxingxia 已提交
2742
  | options | Object                          | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。仅支持&nbsp;'utf-8'。<br/>约束:offset+length<=buffer.size。  |
Z
zengyawen 已提交
2743

Z
zhangxingxia 已提交
2744
**返回值:**
H
HelloCrease 已提交
2745 2746
  | 类型                    | 说明       |
  | --------------------- | -------- |
H
haonan_7 已提交
2747
  | Promise&lt;number&gt; | Promise对象。返回实际写入的长度。 |
Z
zengyawen 已提交
2748

Z
zhangxingxia 已提交
2749
**示例:**
Z
zhangxingxia 已提交
2750
  ```js
Z
zhangxingxia 已提交
2751
  let ss= fileio.createStreamSync(path, "r+");
Z
zhangxingxia 已提交
2752
  ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){
H
haonan_7 已提交
2753
      console.info("write succeed and size is:"+ number);
Z
zhangxingxia 已提交
2754 2755 2756
  }).catch(function(err){
      console.info("write failed with error:"+ err);
  });
Z
zengyawen 已提交
2757 2758 2759 2760 2761
  ```


### write<sup>7+</sup>

2762 2763 2764 2765 2766 2767
write(buffer: ArrayBuffer | string, options: {
    offset?: number;
    length?: number;
    position?: number;
    encoding?: string;
}, callback: AsyncCallback&lt;number&gt;): void
Z
zengyawen 已提交
2768

H
haonan_7 已提交
2769
将数据写入流文件,使用callback异步回调。
Z
zengyawen 已提交
2770

2771 2772
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2773
**参数:**
Z
update  
zhangxingxia 已提交
2774 2775 2776
  | 参数名   | 类型                            | 必填 | 说明                                                         |
  | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
  | buffer   | ArrayBuffer&nbsp;\|&nbsp;string | 是   | 待写入文件的数据,可来自缓冲区或字符串。                     |
Z
zhangxingxia 已提交
2777
  | options  | Object                          | 否   | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。仅支持&nbsp;'utf-8'。<br/>约束:offset+length<=buffer.size。 |
Z
update  
zhangxingxia 已提交
2778
  | callback | AsyncCallback&lt;number&gt;     | 是   | 异步写入完成后执行的回调函数。                               |
Z
zengyawen 已提交
2779

Z
zhangxingxia 已提交
2780
**示例:**
Z
zhangxingxia 已提交
2781
  ```js
Z
zhangxingxia 已提交
2782
  let ss= fileio.createStreamSync(path, "r+");
Z
zengyawen 已提交
2783
  ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) {
Z
zhangxingxia 已提交
2784
      if (bytesWritten) {
Z
zhangxingxia 已提交
2785
         // do something
H
haonan_7 已提交
2786
         console.info("write succeed and size is:"+ bytesWritten);
Z
zengyawen 已提交
2787 2788 2789 2790 2791
      }
  });
  ```


Z
zengyawen 已提交
2792
### writeSync<sup>7+</sup>
Z
zengyawen 已提交
2793

2794 2795 2796 2797 2798 2799
writeSync(buffer: ArrayBuffer | string, options?: {
    offset?: number;
    length?: number;
    position?: number;
    encoding?: string;
}): number
Z
zengyawen 已提交
2800

Z
zengyawen 已提交
2801
以同步方法将数据写入流文件。
Z
zengyawen 已提交
2802

2803 2804
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2805
**参数:**
H
HelloCrease 已提交
2806 2807 2808
  | 参数名     | 类型                              | 必填   | 说明                                       |
  | ------- | ------------------------------- | ---- | ---------------------------------------- |
  | buffer  | ArrayBuffer&nbsp;\|&nbsp;string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
Z
zhangxingxia 已提交
2809
  | options | Object                          | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。仅支持&nbsp;'utf-8'。<br/>约束:offset+length<=buffer.size。  |
Z
zengyawen 已提交
2810

Z
zhangxingxia 已提交
2811
**返回值:**
H
HelloCrease 已提交
2812 2813
  | 类型     | 说明       |
  | ------ | -------- |
Z
zengyawen 已提交
2814
  | number | 实际写入的长度。 |
Z
zengyawen 已提交
2815

Z
zhangxingxia 已提交
2816
**示例:**
Z
zhangxingxia 已提交
2817
  ```js
Z
zhangxingxia 已提交
2818
  let ss= fileio.createStreamSync(path,"r+");
Z
zengyawen 已提交
2819 2820 2821 2822 2823 2824
  let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'});
  ```


### read<sup>7+</sup>

2825 2826 2827 2828 2829
read(buffer: ArrayBuffer, options?: {
    position?: number;
    offset?: number;
    length?: number;
}): Promise&lt;ReadOut&gt;
Z
zengyawen 已提交
2830

H
haonan_7 已提交
2831
从流文件读取数据,使用Promise异步回调。
Z
zengyawen 已提交
2832

2833 2834
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2835
**参数:**
H
HelloCrease 已提交
2836 2837 2838
  | 参数名     | 类型          | 必填   | 说明                                       |
  | ------- | ----------- | ---- | ---------------------------------------- |
  | buffer  | ArrayBuffer | 是    | 用于读取文件的缓冲区。                              |
Z
zhangxingxia 已提交
2839
  | options | Object      | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>约束:offset+length<=buffer.size。  |
Z
zengyawen 已提交
2840

Z
zhangxingxia 已提交
2841
**返回值:**
H
HelloCrease 已提交
2842 2843
  | 类型                                 | 说明     |
  | ---------------------------------- | ------ |
H
haonan_7 已提交
2844
  | Promise&lt;[ReadOut](#readout)&gt; | Promise对象。返回读取的结果。 |
Z
zengyawen 已提交
2845

Z
zhangxingxia 已提交
2846
**示例:**
Z
zhangxingxia 已提交
2847
  ```js
Z
zhangxingxia 已提交
2848
  let ss = fileio.createStreamSync(path, "r+");
Z
zhangxingxia 已提交
2849
  ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){
H
haonan_7 已提交
2850
      console.info("read data succeed");
W
wangbo 已提交
2851
      console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
Z
zhangxingxia 已提交
2852 2853 2854
  }).catch(function(err){
      console.info("read data failed with error:"+ err);
  });
Z
zengyawen 已提交
2855 2856 2857 2858 2859
  ```


### read<sup>7+</sup>

2860 2861 2862 2863 2864
read(buffer: ArrayBuffer, options: {
    position?: number;
    offset?: number;
    length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void
Z
zengyawen 已提交
2865

H
haonan_7 已提交
2866
从流文件读取数据,使用callback异步回调。
Z
zengyawen 已提交
2867

2868 2869
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2870
**参数:**
H
HelloCrease 已提交
2871 2872 2873
  | 参数名      | 类型                                       | 必填   | 说明                                       |
  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
  | buffer   | ArrayBuffer                              | 是    | 用于读取文件的缓冲区。                              |
Z
zhangxingxia 已提交
2874
  | options  | Object                                   | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>约束:offset+length<=buffer.size。  |
H
HelloCrease 已提交
2875
  | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | 是    | 异步从流文件读取数据之后的回调。                         |
Z
zengyawen 已提交
2876

Z
zhangxingxia 已提交
2877
**示例:**
Z
zhangxingxia 已提交
2878
  ```js
Z
zhangxingxia 已提交
2879
  let ss = fileio.createStreamSync(path, "r+");
Z
zengyawen 已提交
2880
  ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
Z
zhangxingxia 已提交
2881
      if (readOut) {
H
haonan_7 已提交
2882
          console.info("read data succeed");
Z
zhangxingxia 已提交
2883
          console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
Z
zengyawen 已提交
2884 2885
      }
  });
Z
zengyawen 已提交
2886
  ```
Z
zengyawen 已提交
2887 2888


Z
zengyawen 已提交
2889
### readSync<sup>7+</sup>
Z
zengyawen 已提交
2890

2891 2892 2893 2894 2895
readSync(buffer: ArrayBuffer, options?: {
    position?: number;
    offset?: number;
    length?: number;
}): number
Z
zengyawen 已提交
2896 2897 2898

以同步方法从流文件读取数据。

2899 2900
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2901
**参数:**
Z
zhangxingxia 已提交
2902

H
HelloCrease 已提交
2903 2904 2905
  | 参数名     | 类型          | 必填   | 说明                                       |
  | ------- | ----------- | ---- | ---------------------------------------- |
  | buffer  | ArrayBuffer | 是    | 用于读取文件的缓冲区。                              |
Z
zhangxingxia 已提交
2906
  | options | Object      | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>约束:offset+length<=buffer.size。  |
Z
zhangxingxia 已提交
2907

Z
zhangxingxia 已提交
2908
**返回值:**
Z
zhangxingxia 已提交
2909

H
HelloCrease 已提交
2910 2911
  | 类型     | 说明       |
  | ------ | -------- |
Z
zengyawen 已提交
2912
  | number | 实际读取的长度。 |
Z
zhangxingxia 已提交
2913

Z
zhangxingxia 已提交
2914
**示例:**
Z
zhangxingxia 已提交
2915
  ```js
Z
zhangxingxia 已提交
2916
  let ss = fileio.createStreamSync(path, "r+");
Z
zengyawen 已提交
2917
  let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5});
Z
zengyawen 已提交
2918
  ```
Z
zengyawen 已提交
2919 2920


Z
zengyawen 已提交
2921
## Dir
Z
zengyawen 已提交
2922

Z
zengyawen 已提交
2923 2924 2925 2926 2927 2928 2929
管理目录,在调用Dir的方法前,需要先通过[opendir()](#fileioopendir)方法(同步或异步)来构建一个Dir实例。


### read

read(): Promise&lt;Dirent&gt;

H
haonan_7 已提交
2930
读取下一个目录项,使用Promise异步回调。
Z
zengyawen 已提交
2931

2932 2933
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2934
**返回值:**
H
HelloCrease 已提交
2935 2936
  | 类型                               | 说明            |
  | -------------------------------- | ------------- |
H
haonan_7 已提交
2937
  | Promise&lt;[Dirent](#dirent)&gt; | Promise对象。返回表示异步读取目录项的结果。 |
Z
zengyawen 已提交
2938

Z
zhangxingxia 已提交
2939
**示例:**
Z
zhangxingxia 已提交
2940
  ```js
W
wangbo 已提交
2941
  let dir = fileio.opendirSync(path);
Z
zhangxingxia 已提交
2942
  dir.read().then(function (dirent){
H
haonan_7 已提交
2943
      console.log("read succeed:"+JSON.stringify(dirent));
Z
zhangxingxia 已提交
2944 2945 2946
  }).catch(function(err){
      console.info("read failed with error:"+ err);
  });
Z
zengyawen 已提交
2947 2948 2949 2950 2951 2952 2953
  ```


### read

read(callback: AsyncCallback&lt;Dirent&gt;): void

H
haonan_7 已提交
2954
读取下一个目录项,使用callback异步回调。
Z
zengyawen 已提交
2955

2956 2957
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2958
**参数:**
H
HelloCrease 已提交
2959 2960 2961
  | 参数名      | 类型                                     | 必填   | 说明               |
  | -------- | -------------------------------------- | ---- | ---------------- |
  | callback | AsyncCallback&lt;[Dirent](#dirent)&gt; | 是    | 异步读取下一个目录项之后的回调。 |
Z
zengyawen 已提交
2962

Z
zhangxingxia 已提交
2963
**示例:**
Z
zhangxingxia 已提交
2964
  ```js
W
wangbo 已提交
2965
  let dir = fileio.opendirSync(path);
Z
zengyawen 已提交
2966
  dir.read(function (err, dirent) {
Z
zhangxingxia 已提交
2967
      if (dirent) {
Z
zhangxingxia 已提交
2968
          // do something
H
haonan_7 已提交
2969
          console.log("read succeed:"+JSON.stringify(dirent));
Z
zengyawen 已提交
2970 2971 2972
      }
  });
  ```
Z
zengyawen 已提交
2973 2974


Z
zengyawen 已提交
2975
### readSync
Z
zengyawen 已提交
2976

Z
zengyawen 已提交
2977
readSync(): Dirent
Z
zengyawen 已提交
2978

Z
zengyawen 已提交
2979
同步读取下一个目录项。
Z
zengyawen 已提交
2980

2981 2982
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
2983
**返回值:**
H
HelloCrease 已提交
2984 2985
  | 类型                | 说明       |
  | ----------------- | -------- |
Z
zengyawen 已提交
2986
  | [Dirent](#dirent) | 表示一个目录项。 |
Z
zengyawen 已提交
2987

Z
zhangxingxia 已提交
2988
**示例:**
Z
zhangxingxia 已提交
2989
  ```js
W
wangbo 已提交
2990
  let dir = fileio.opendirSync(path);
Z
zengyawen 已提交
2991 2992
  let dirent = dir.readSync();
  ```
Z
zengyawen 已提交
2993 2994


W
wangbo 已提交
2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028
### close<sup>7+</sup>

close(): Promise&lt;void&gt;

异步关闭目录,使用promise形式返回结果。目录被关闭后,Dir中持有的文件描述将被释放,后续将无法从Dir中读取目录项。

**系统能力**:SystemCapability.FileManagement.File.FileIO

**示例:**
  ```js
  let dir = fileio.opendirSync(path);
  dir.close().then(function(err){
      console.info("close dir successfully");
  });
  ```


  ### close<sup>7+</sup>

close(callback: AsyncCallback&lt;void&gt;): void

异步关闭目录,使用callback形式返回结果。目录被关闭后,Dir中持有的文件描述将被释放,后续将无法从Dir中读取目录项。

**系统能力**:SystemCapability.FileManagement.File.FileIO

**示例:**
  ```js
  let dir = fileio.opendirSync(path);
  dir.close(function(err){
      console.info("close dir successfully");
  });
  ```


Z
zengyawen 已提交
3029
### closeSync
Z
zengyawen 已提交
3030

Z
zengyawen 已提交
3031
closeSync(): void
Z
zengyawen 已提交
3032

Z
zengyawen 已提交
3033
用于关闭目录。目录被关闭后,Dir中持有的文件描述将被释放,后续将无法从Dir中读取目录项。
Z
zengyawen 已提交
3034

3035 3036
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
3037
**示例:**
Z
zhangxingxia 已提交
3038
  ```js
W
wangbo 已提交
3039
  let dir = fileio.opendirSync(path);
Z
zengyawen 已提交
3040 3041
  dir.closeSync();
  ```
Z
zengyawen 已提交
3042 3043


Z
zengyawen 已提交
3044
## Dirent
Z
zengyawen 已提交
3045

Z
zengyawen 已提交
3046
在调用Dirent的方法前,需要先通过[dir.read()](#read)方法(同步或异步)来构建一个Dirent实例。
Z
zengyawen 已提交
3047

3048
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.File.FileIO。
Z
zengyawen 已提交
3049

Z
zengyawen 已提交
3050
### 属性
Z
zengyawen 已提交
3051

H
HelloCrease 已提交
3052 3053 3054
| 名称   | 参数类型   | 可读   | 可写   | 说明      |
| ---- | ------ | ---- | ---- | ------- |
| name | string | 是    | 否    | 目录项的名称。 |
Z
zengyawen 已提交
3055 3056


Z
zengyawen 已提交
3057
### isBlockDevice
Z
zengyawen 已提交
3058

Z
zengyawen 已提交
3059
isBlockDevice(): boolean
Z
zengyawen 已提交
3060

Z
zhangxingxia 已提交
3061
用于判断当前目录项是否是块特殊文件。一个块特殊文件只能以块为粒度进行访问,且访问的时候带缓存。
Z
zengyawen 已提交
3062

3063 3064
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
3065
**返回值:**
H
HelloCrease 已提交
3066 3067
  | 类型      | 说明               |
  | ------- | ---------------- |
Z
zhangxingxia 已提交
3068
  | boolean | 表示当前目录项是否是块特殊设备。 |
Z
zengyawen 已提交
3069

Z
zhangxingxia 已提交
3070
**示例:**
Z
zhangxingxia 已提交
3071
  ```js
W
wangbo 已提交
3072
  let dir = fileio.opendirSync(path);
Z
zengyawen 已提交
3073 3074
  let isBLockDevice = dir.readSync().isBlockDevice();
  ```
Z
zengyawen 已提交
3075 3076


Z
zengyawen 已提交
3077
### isCharacterDevice
Z
zengyawen 已提交
3078

Z
zengyawen 已提交
3079
isCharacterDevice(): boolean
Z
zengyawen 已提交
3080

Z
zhangxingxia 已提交
3081
用于判断当前目录项是否是字符特殊设备。一个字符特殊设备可进行随机访问,且访问的时候不带缓存。
Z
zengyawen 已提交
3082

3083 3084
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
3085
**返回值:**
H
HelloCrease 已提交
3086 3087
  | 类型      | 说明                |
  | ------- | ----------------- |
Z
zhangxingxia 已提交
3088
  | boolean | 表示当前目录项是否是字符特殊设备。 |
Z
zengyawen 已提交
3089

Z
zhangxingxia 已提交
3090
**示例:**
Z
zhangxingxia 已提交
3091
  ```js
W
wangbo 已提交
3092
  let dir = fileio.opendirSync(path);
Z
zengyawen 已提交
3093 3094
  let isCharacterDevice = dir.readSync().isCharacterDevice(); 
  ```
Z
zengyawen 已提交
3095 3096


Z
zengyawen 已提交
3097
### isDirectory
Z
zengyawen 已提交
3098

Z
zengyawen 已提交
3099
isDirectory(): boolean
Z
zengyawen 已提交
3100

Z
zhangxingxia 已提交
3101
用于判断当前目录项是否是目录。
Z
zengyawen 已提交
3102

3103 3104
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
3105
**返回值:**
H
HelloCrease 已提交
3106 3107
  | 类型      | 说明            |
  | ------- | ------------- |
Z
zhangxingxia 已提交
3108
  | boolean | 表示当前目录项是否是目录。 |
Z
zengyawen 已提交
3109

Z
zhangxingxia 已提交
3110
**示例:**
Z
zhangxingxia 已提交
3111
  ```js
W
wangbo 已提交
3112
  let dir = fileio.opendirSync(path);
Z
zengyawen 已提交
3113 3114
  let isDirectory = dir.readSync().isDirectory(); 
  ```
Z
zengyawen 已提交
3115 3116


Z
zengyawen 已提交
3117
### isFIFO
Z
zengyawen 已提交
3118

Z
zengyawen 已提交
3119
isFIFO(): boolean
Z
zengyawen 已提交
3120

Z
zhangxingxia 已提交
3121
用于判断当前目录项是否是命名管道(有时也称为FIFO)。命名管道通常用于进程间通信。
Z
zengyawen 已提交
3122

3123 3124
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
3125
**返回值:**
H
HelloCrease 已提交
3126 3127
  | 类型      | 说明              |
  | ------- | --------------- |
Z
zhangxingxia 已提交
3128
  | boolean | 表示当前目录项是否是FIFO。 |
Z
zengyawen 已提交
3129

Z
zhangxingxia 已提交
3130
**示例:**
Z
zhangxingxia 已提交
3131
  ```js
W
wangbo 已提交
3132
  let dir = fileio.opendirSync(path);
Z
zengyawen 已提交
3133 3134
  let isFIFO = dir.readSync().isFIFO(); 
  ```
Z
zengyawen 已提交
3135 3136


Z
zengyawen 已提交
3137
### isFile
Z
zengyawen 已提交
3138

Z
zengyawen 已提交
3139
isFile(): boolean
Z
zengyawen 已提交
3140

Z
zhangxingxia 已提交
3141
用于判断当前目录项是否是普通文件。
Z
zengyawen 已提交
3142

3143 3144
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
3145
**返回值:**
H
HelloCrease 已提交
3146 3147
  | 类型      | 说明              |
  | ------- | --------------- |
Z
zhangxingxia 已提交
3148
  | boolean | 表示当前目录项是否是普通文件。 |
Z
zengyawen 已提交
3149

Z
zhangxingxia 已提交
3150
**示例:**
Z
zhangxingxia 已提交
3151
  ```js
W
wangbo 已提交
3152
  let dir = fileio.opendirSync(path);
Z
zengyawen 已提交
3153 3154
  let isFile = dir.readSync().isFile(); 
  ```
Z
zengyawen 已提交
3155 3156


Z
zengyawen 已提交
3157
### isSocket
Z
zengyawen 已提交
3158

Z
zengyawen 已提交
3159
isSocket(): boolean
Z
zengyawen 已提交
3160

Z
zhangxingxia 已提交
3161
用于判断当前目录项是否是套接字。
Z
zengyawen 已提交
3162

3163 3164
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
3165
**返回值:**
H
HelloCrease 已提交
3166 3167
  | 类型      | 说明             |
  | ------- | -------------- |
Z
zhangxingxia 已提交
3168
  | boolean | 表示当前目录项是否是套接字。 |
Z
zengyawen 已提交
3169

Z
zhangxingxia 已提交
3170
**示例:**
Z
zhangxingxia 已提交
3171
  ```js
W
wangbo 已提交
3172
  let dir = fileio.opendirSync(dpath);
Z
zengyawen 已提交
3173 3174
  let isSocket = dir.readSync().isSocket(); 
  ```
Z
zengyawen 已提交
3175 3176


Z
zengyawen 已提交
3177
### isSymbolicLink
Z
zengyawen 已提交
3178

Z
zengyawen 已提交
3179
isSymbolicLink(): boolean
Z
zengyawen 已提交
3180

Z
zhangxingxia 已提交
3181
用于判断当前目录项是否是符号链接。
Z
zengyawen 已提交
3182

3183 3184
**系统能力**:SystemCapability.FileManagement.File.FileIO

Z
zhangxingxia 已提交
3185
**返回值:**
H
HelloCrease 已提交
3186 3187
  | 类型      | 说明              |
  | ------- | --------------- |
Z
zhangxingxia 已提交
3188
  | boolean | 表示当前目录项是否是符号链接。 |
Z
zengyawen 已提交
3189

Z
zhangxingxia 已提交
3190
**示例:**
Z
zhangxingxia 已提交
3191
  ```js
W
wangbo 已提交
3192
  let dir = fileio.opendirSync(path);
Z
zengyawen 已提交
3193 3194
  let isSymbolicLink = dir.readSync().isSymbolicLink();
  ```