• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.fs (文件管理)
2
3该模块为基础文件操作API,提供基础文件操作能力,包括文件基本管理、文件目录管理、文件信息统计、文件流式读写等常用功能。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```js
12import fs from '@ohos.file.fs';
13```
14
15## 使用说明
16
17使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考:
18
19**Stage模型**
20
21 ```js
22import UIAbility from '@ohos.app.ability.UIAbility';
23
24export default class EntryAbility extends UIAbility {
25    onWindowStageCreate(windowStage) {
26        let context = this.context;
27        let pathDir = context.filesDir;
28    }
29}
30 ```
31
32**FA模型**
33
34 ```js
35 import featureAbility from '@ohos.ability.featureAbility';
36
37 let context = featureAbility.getContext();
38 context.getFilesDir().then((data) => {
39      let pathDir = data;
40 })
41 ```
42
43FA模型context的具体获取方法参见[FA模型](js-apis-inner-app-context.md#Context模块)。
44
45## fs.stat
46
47stat(file: string|number): Promise<Stat>
48
49获取文件详细属性信息,使用Promise异步回调。
50
51**系统能力**:SystemCapability.FileManagement.File.FileIO
52
53**参数:**
54
55| 参数名 | 类型   | 必填 | 说明                       |
56| ------ | ------ | ---- | -------------------------- |
57| file   | string\|number | 是   | 文件应用沙箱路径path或已打开的文件描述符fd。 |
58
59**返回值:**
60
61  | 类型                           | 说明         |
62  | ---------------------------- | ---------- |
63  | Promise<[Stat](#stat)> | Promise对象。返回文件的具体信息。 |
64
65**错误码:**
66
67接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
68
69**示例:**
70
71  ```js
72  let filePath = pathDir + "/test.txt";
73  fs.stat(filePath).then((stat) => {
74      console.info("get file info succeed, the size of file is " + stat.size);
75  }).catch((err) => {
76      console.info("get file info failed with error message: " + err.message + ", error code: " + err.code);
77  });
78  ```
79
80## fs.stat
81
82stat(file: string|number, callback: AsyncCallback<Stat>): void
83
84获取文件详细属性信息,使用callback异步回调。
85
86**系统能力**:SystemCapability.FileManagement.File.FileIO
87
88**参数:**
89
90| 参数名   | 类型                               | 必填 | 说明                           |
91| -------- | ---------------------------------- | ---- | ------------------------------ |
92| file     | string\|number                            | 是   | 文件应用沙箱路径path或已打开的文件描述符fd。     |
93| callback | AsyncCallback<[Stat](#stat)> | 是   | 异步获取文件的信息之后的回调。 |
94
95**错误码:**
96
97接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
98
99**示例:**
100
101  ```js
102  fs.stat(pathDir, (err, stat) => {
103    if (err) {
104      console.info("get file info failed with error message: " + err.message + ", error code: " + err.code);
105    } else {
106      console.info("get file info succeed, the size of file is " + stat.size);
107    }
108  });
109  ```
110
111## fs.statSync
112
113statSync(file: string|number): Stat
114
115以同步方法获取文件详细属性信息。
116
117**系统能力**:SystemCapability.FileManagement.File.FileIO
118
119**参数:**
120
121| 参数名 | 类型   | 必填 | 说明                       |
122| ------ | ------ | ---- | -------------------------- |
123| file   | string\|number | 是   | 文件应用沙箱路径path或已打开的文件描述符fd。 |
124
125**返回值:**
126
127  | 类型            | 说明         |
128  | ------------- | ---------- |
129  | [Stat](#stat) | 表示文件的具体信息。 |
130
131**错误码:**
132
133接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
134
135**示例:**
136
137  ```js
138  let stat = fs.statSync(pathDir);
139  console.info("get file info succeed, the size of file is " + stat.size);
140  ```
141
142## fs.access
143
144access(path: string): Promise<boolean>
145
146检查文件是否存在,使用Promise异步回调。
147
148**系统能力**:SystemCapability.FileManagement.File.FileIO
149
150**参数:**
151
152| 参数名 | 类型   | 必填 | 说明                                                         |
153| ------ | ------ | ---- | ------------------------------------------------------------ |
154| path   | string | 是   | 文件应用沙箱路径。                                   |
155
156**返回值:**
157
158  | 类型                  | 说明                           |
159  | ------------------- | ---------------------------- |
160  | Promise<boolean> | Promise对象。返回boolean,表示文件是否存在。 |
161
162**错误码:**
163
164接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
165
166**示例:**
167
168  ```js
169  let filePath = pathDir + "/test.txt";
170  fs.access(filePath).then((res) => {
171    if (res) {
172      console.info("file exists");
173    }
174  }).catch((err) => {
175    console.info("access failed with error message: " + err.message + ", error code: " + err.code);
176  });
177  ```
178
179## fs.access
180
181access(path: string, callback: AsyncCallback<boolean>): void
182
183检查文件是否存在,使用callback异步回调。
184
185**系统能力**:SystemCapability.FileManagement.File.FileIO
186
187**参数:**
188
189| 参数名   | 类型                      | 必填 | 说明                                                         |
190| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
191| path     | string                    | 是   | 文件应用沙箱路径。                                   |
192| callback | AsyncCallback<boolean> | 是   | 异步检查文件是否存在的回调,如果存在,回调返回true,否则返回false。 |
193
194**错误码:**
195
196接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
197
198**示例:**
199
200  ```js
201  let filePath = pathDir + "/test.txt";
202  fs.access(filePath, (err, res) => {
203    if (err) {
204      console.info("access failed with error message: " + err.message + ", error code: " + err.code);
205    } else {
206      if (res) {
207        console.info("file exists");
208      }
209    }
210  });
211  ```
212
213## fs.accessSync
214
215accessSync(path: string): boolean
216
217以同步方法检查文件是否存在。
218
219**系统能力**:SystemCapability.FileManagement.File.FileIO
220
221**参数:**
222
223| 参数名 | 类型   | 必填 | 说明                                                         |
224| ------ | ------ | ---- | ------------------------------------------------------------ |
225| path   | string | 是   | 文件应用沙箱路径。                                   |
226
227**返回值:**
228
229  | 类型                  | 说明                           |
230  | ------------------- | ---------------------------- |
231  | boolean | 返回true,表示文件存在;返回false,表示文件不存在。 |
232
233**错误码:**
234
235接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
236
237**示例:**
238
239  ```js
240  let filePath = pathDir + "/test.txt";
241  try {
242      let res = fs.accessSync(filePath);
243      if (res) {
244        console.info("file exists");
245      }
246  } catch(err) {
247      console.info("accessSync failed with error message: " + err.message + ", error code: " + err.code);
248  }
249  ```
250
251
252## fs.close
253
254close(file: number|File): Promise<void>
255
256关闭文件,使用Promise异步回调。
257
258**系统能力**:SystemCapability.FileManagement.File.FileIO
259
260**参数:**
261
262  | 参数名  | 类型     | 必填   | 说明           |
263  | ---- | ------ | ---- | ------------ |
264  | file   | number\|[File](#file) | 是    | 已打开的File对象或已打开的文件描述符fd。 |
265
266**返回值:**
267
268  | 类型                  | 说明                           |
269  | ------------------- | ---------------------------- |
270  | Promise<void> | Promise对象。无返回值。 |
271
272**错误码:**
273
274接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
275
276**示例:**
277
278  ```js
279  let filePath = pathDir + "/test.txt";
280  let file = fs.openSync(filePath);
281  fs.close(file).then(() => {
282      console.info("close file succeed");
283      fs.closeSync(file);
284  }).catch((err) => {
285      console.info("close file failed with error message: " + err.message + ", error code: " + err.code);
286  });
287  ```
288
289## fs.close
290
291close(file: number|File, callback: AsyncCallback<void>): void
292
293关闭文件,使用callback异步回调。
294
295**系统能力**:SystemCapability.FileManagement.File.FileIO
296
297**参数:**
298
299  | 参数名      | 类型                        | 必填   | 说明           |
300  | -------- | ------------------------- | ---- | ------------ |
301  | file       | number\|[File](#file)                  | 是    | 已打开的File对象或已打开的文件描述符fd。 |
302  | callback | AsyncCallback<void> | 是    | 异步关闭文件之后的回调。 |
303
304**错误码:**
305
306接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
307
308**示例:**
309
310  ```js
311  let filePath = pathDir + "/test.txt";
312  let file = fs.openSync(filePath);
313  fs.close(file, (err) => {
314    if (err) {
315      console.info("close file failed with error message: " + err.message + ", error code: " + err.code);
316    } else {
317      console.info("close file success");
318    }
319  });
320  ```
321
322## fs.closeSync
323
324closeSync(file: number|File): void
325
326以同步方法关闭文件。
327
328**系统能力**:SystemCapability.FileManagement.File.FileIO
329
330**参数:**
331
332  | 参数名  | 类型     | 必填   | 说明           |
333  | ---- | ------ | ---- | ------------ |
334  | file   | number\|[File](#file) | 是    | 已打开的File对象或已打开的文件描述符fd。 |
335
336**错误码:**
337
338接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
339
340**示例:**
341
342  ```js
343  let filePath = pathDir + "/test.txt";
344  let file = fs.openSync(filePath);
345  fs.closeSync(file);
346  ```
347
348## fs.copyFile
349
350copyFile(src: string|number, dest: string|number, mode?: number): Promise<void>
351
352复制文件,使用Promise异步回调。
353
354**系统能力**:SystemCapability.FileManagement.File.FileIO
355
356**参数:**
357
358  | 参数名  | 类型                         | 必填   | 说明                                       |
359  | ---- | -------------------------- | ---- | ---------------------------------------- |
360  | src  | string\|number | 是    | 待复制文件的路径或待复制文件的文件描述符。                      |
361  | dest | string\|number | 是    | 目标文件路径或目标文件的文件描述符。                          |
362  | mode | number                     | 否    | mode提供覆盖文件的选项,当前仅支持0,且默认为0。<br/>0:完全覆盖目标文件。 |
363
364**返回值:**
365
366  | 类型                  | 说明                           |
367  | ------------------- | ---------------------------- |
368  | Promise&lt;void&gt; | Promise对象。无返回值。 |
369
370**错误码:**
371
372接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
373
374**示例:**
375
376  ```js
377  let srcPath = pathDir + "/srcDir/test.txt";
378  let dstPath = pathDir + "/dstDir/test.txt";
379  fs.copyFile(srcPath, dstPath).then(() => {
380      console.info("copy file succeed");
381  }).catch((err) => {
382      console.info("copy file failed with error message: " + err.message + ", error code: " + err.code);
383  });
384  ```
385
386## fs.copyFile
387
388copyFile(src: string|number, dest: string|number, mode?: number, callback: AsyncCallback&lt;void&gt;): void
389
390复制文件,使用callback异步回调。
391
392**系统能力**:SystemCapability.FileManagement.File.FileIO
393
394**参数:**
395
396  | 参数名      | 类型                         | 必填   | 说明                                       |
397  | -------- | -------------------------- | ---- | ---------------------------------------- |
398  | src      | string\|number | 是    | 待复制文件的路径或待复制文件的文件描述符。                      |
399  | dest     | string\|number | 是    | 目标文件路径或目标文件的文件描述符。                          |
400  | mode     | number                     | 否    | mode提供覆盖文件的选项,当前仅支持0,且默认为0。<br/>0:完全覆盖目标文件,未覆盖部分将被裁切掉。 |
401  | callback | AsyncCallback&lt;void&gt;  | 是    | 异步复制文件之后的回调。                             |
402
403**错误码:**
404
405接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
406
407**示例:**
408
409  ```js
410  let srcPath = pathDir + "/srcDir/test.txt";
411  let dstPath = pathDir + "/dstDir/test.txt";
412  fs.copyFile(srcPath, dstPath, (err) => {
413    if (err) {
414      console.info("copy file failed with error message: " + err.message + ", error code: " + err.code);
415    } else {
416      console.info("copy file success");
417    }
418  });
419  ```
420
421
422## fs.copyFileSync
423
424copyFileSync(src: string|number, dest: string|number, mode?: number): void
425
426以同步方法复制文件。
427
428**系统能力**:SystemCapability.FileManagement.File.FileIO
429
430**参数:**
431
432  | 参数名  | 类型                         | 必填   | 说明                                       |
433  | ---- | -------------------------- | ---- | ---------------------------------------- |
434  | src  | string\|number | 是    | 待复制文件的路径或待复制文件的文件描述符。                      |
435  | dest | string\|number | 是    | 目标文件路径或目标文件的文件描述符。                          |
436  | mode | number                     | 否    | mode提供覆盖文件的选项,当前仅支持0,且默认为0。<br/>0:完全覆盖目标文件,未覆盖部分将被裁切掉。 |
437
438**错误码:**
439
440接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
441
442**示例:**
443
444  ```js
445  let srcPath = pathDir + "/srcDir/test.txt";
446  let dstPath = pathDir + "/dstDir/test.txt";
447  fs.copyFileSync(srcPath, dstPath);
448  ```
449
450## fs.mkdir
451
452mkdir(path: string): Promise&lt;void&gt;
453
454创建目录,使用Promise异步回调。
455
456**系统能力**:SystemCapability.FileManagement.File.FileIO
457
458**参数:**
459
460| 参数名 | 类型   | 必填 | 说明                                                         |
461| ------ | ------ | ---- | ------------------------------------------------------------ |
462| path   | string | 是   | 目录的应用沙箱路径。                                   |
463
464**返回值:**
465
466  | 类型                  | 说明                           |
467  | ------------------- | ---------------------------- |
468  | Promise&lt;void&gt; | Promise对象。无返回值。 |
469
470**错误码:**
471
472接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
473
474**示例:**
475
476  ```js
477  let dirPath = pathDir + "/testDir";
478  fs.mkdir(dirPath).then(() => {
479      console.info("mkdir succeed");
480  }).catch((err) => {
481      console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
482  });
483  ```
484
485## fs.mkdir
486
487mkdir(path: string, callback: AsyncCallback&lt;void&gt;): void
488
489创建目录,使用callback异步回调。
490
491**系统能力**:SystemCapability.FileManagement.File.FileIO
492
493**参数:**
494
495| 参数名   | 类型                      | 必填 | 说明                                                         |
496| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
497| path     | string                    | 是   | 目录的应用沙箱路径。                                   |
498| callback | AsyncCallback&lt;void&gt; | 是   | 异步创建目录操作完成之后的回调。                             |
499
500**错误码:**
501
502接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
503
504**示例:**
505
506  ```js
507  let dirPath = pathDir + "/testDir";
508  fs.mkdir(dirPath, (err) => {
509    if (err) {
510      console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
511    } else {
512      console.info("mkdir success");
513    }
514  });
515  ```
516
517## fs.mkdirSync
518
519mkdirSync(path: string): void
520
521以同步方法创建目录。
522
523**系统能力**:SystemCapability.FileManagement.File.FileIO
524
525**参数:**
526
527| 参数名 | 类型   | 必填 | 说明                                                         |
528| ------ | ------ | ---- | ------------------------------------------------------------ |
529| path   | string | 是   | 目录的应用沙箱路径。                                   |
530
531**错误码:**
532
533接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
534
535**示例:**
536
537  ```js
538  let dirPath = pathDir + "/testDir";
539  fs.mkdirSync(dirPath);
540  ```
541
542## fs.open
543
544open(path: string, mode?: number): Promise&lt;File&gt;
545
546打开文件,使用Promise异步回调。支持使用URI打开文件。
547
548**系统能力**:SystemCapability.FileManagement.File.FileIO
549
550**参数:**
551
552| 参数名 | 类型   | 必填 | 说明                                                         |
553| ------ | ------ | ---- | ------------------------------------------------------------ |
554| path   | string | 是   | 文件的应用沙箱路径或文件URI。                                   |
555| mode  | number | 否   | 打开文件的[选项](#openmode),必须指定如下选项中的一个,默认以只读方式打开:<br/>-&nbsp;OpenMode.READ_ONLY(0o0):只读打开。<br/>-&nbsp;OpenMode.WRITE_ONLY(0o1):只写打开。<br/>-&nbsp;OpenMode.READ_WRITE(0o2):读写打开。<br/>给定如下功能选项,以按位或的方式追加,默认不给定任何额外选项:<br/>-&nbsp;OpenMode.CREATE(0o100):若文件不存在,则创建文件。<br/>-&nbsp;OpenMode.TRUNC(0o1000):如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。<br/>-&nbsp;OpenMode.APPEND(0o2000):以追加方式打开,后续写将追加到文件末尾。<br/>-&nbsp;OpenMode.NONBLOCK(0o4000):如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续&nbsp;IO&nbsp;进行非阻塞操作。<br/>-&nbsp;OpenMode.DIR(0o200000):如果path不指向目录,则出错。<br/>-&nbsp;OpenMode.NOFOLLOW(0o400000):如果path指向符号链接,则出错。<br/>-&nbsp;OpenMode.SYNC(0o4010000):以同步IO的方式打开文件。 |
556
557**返回值:**
558
559  | 类型                    | 说明          |
560  | --------------------- | ----------- |
561  | Promise&lt;[File](#file)&gt; | Promise对象。返回File对象。 |
562
563**错误码:**
564
565接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
566
567**示例:**
568
569  ```js
570  let filePath = pathDir + "/test.txt";
571  fs.open(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE).then((file) => {
572      console.info("file fd: " + file.fd);
573  }).catch((err) => {
574      console.info("open file failed with error message: " + err.message + ", error code: " + err.code);
575  });
576  ```
577
578
579## fs.open
580
581open(path: string, mode?: number, callback: AsyncCallback&lt;File&gt;): void
582
583打开文件,使用callback异步回调。支持使用URI打开文件。
584
585**系统能力**:SystemCapability.FileManagement.File.FileIO
586
587**参数:**
588
589| 参数名   | 类型                            | 必填 | 说明                                                         |
590| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
591| path     | string                          | 是   | 文件的应用沙箱路径或URI。                                   |
592| mode  | number | 否   | 打开文件的[选项](#openmode),必须指定如下选项中的一个,默认以只读方式打开:<br/>-&nbsp;OpenMode.READ_ONLY(0o0):只读打开。<br/>-&nbsp;OpenMode.WRITE_ONLY(0o1):只写打开。<br/>-&nbsp;OpenMode.READ_WRITE(0o2):读写打开。<br/>给定如下功能选项,以按位或的方式追加,默认不给定任何额外选项:<br/>-&nbsp;OpenMode.CREATE(0o100):若文件不存在,则创建文件。<br/>-&nbsp;OpenMode.TRUNC(0o1000):如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。<br/>-&nbsp;OpenMode.APPEND(0o2000):以追加方式打开,后续写将追加到文件末尾。<br/>-&nbsp;OpenMode.NONBLOCK(0o4000):如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续&nbsp;IO&nbsp;进行非阻塞操作。<br/>-&nbsp;OpenMode.DIR(0o200000):如果path不指向目录,则出错。<br/>-&nbsp;OpenMode.NOFOLLOW(0o400000):如果path指向符号链接,则出错。<br/>-&nbsp;OpenMode.SYNC(0o4010000):以同步IO的方式打开文件。 |
593
594**错误码:**
595
596接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
597
598**示例:**
599
600  ```js
601  let filePath = pathDir + "/test.txt";
602  fs.open(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE, (err, file) => {
603    if (err) {
604      console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
605    } else {
606      console.info("file fd: " + file.fd);
607    }
608  });
609  ```
610
611## fs.openSync
612
613openSync(path: string, mode?: number): File
614
615以同步方法打开文件。支持使用URI打开文件。
616
617**系统能力**:SystemCapability.FileManagement.File.FileIO
618
619**参数:**
620
621| 参数名 | 类型   | 必填 | 说明                                                         |
622| ------ | ------ | ---- | ------------------------------------------------------------ |
623| path   | string | 是   | 打开文件的应用沙箱路径或URI。                                   |
624| mode  | number | 否   | 打开文件的[选项](#openmode),必须指定如下选项中的一个,默认以只读方式打开:<br/>-&nbsp;OpenMode.READ_ONLY(0o0):只读打开。<br/>-&nbsp;OpenMode.WRITE_ONLY(0o1):只写打开。<br/>-&nbsp;OpenMode.READ_WRITE(0o2):读写打开。<br/>给定如下功能选项,以按位或的方式追加,默认不给定任何额外选项:<br/>-&nbsp;OpenMode.CREATE(0o100):若文件不存在,则创建文件。<br/>-&nbsp;OpenMode.TRUNC(0o1000):如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。<br/>-&nbsp;OpenMode.APPEND(0o2000):以追加方式打开,后续写将追加到文件末尾。<br/>-&nbsp;OpenMode.NONBLOCK(0o4000):如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续&nbsp;IO&nbsp;进行非阻塞操作。<br/>-&nbsp;OpenMode.DIR(0o200000):如果path不指向目录,则出错。<br/>-&nbsp;OpenMode.NOFOLLOW(0o400000):如果path指向符号链接,则出错。<br/>-&nbsp;OpenMode.SYNC(0o4010000):以同步IO的方式打开文件。 |
625
626**返回值:**
627
628  | 类型     | 说明          |
629  | ------ | ----------- |
630  | [File](#file) | 打开的File对象。 |
631
632**错误码:**
633
634接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
635
636**示例:**
637
638  ```js
639  let filePath = pathDir + "/test.txt";
640  let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
641  console.info("file fd: " + file.fd);
642  fs.closeSync(file);
643  ```
644
645## fs.read
646
647read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): Promise&lt;number&gt;
648
649从文件读取数据,使用Promise异步回调。
650
651**系统能力**:SystemCapability.FileManagement.File.FileIO
652
653**参数:**
654
655| 参数名  | 类型        | 必填 | 说明                                                         |
656| ------- | ----------- | ---- | ------------------------------------------------------------ |
657| fd      | number      | 是   | 已打开的文件描述符。                                     |
658| buffer  | ArrayBuffer | 是   | 用于保存读取到的文件数据的缓冲区。                           |
659| options | Object      | 否   | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度。|
660
661**返回值:**
662
663  | 类型                                 | 说明     |
664  | ---------------------------------- | ------ |
665  | Promise&lt;number&gt; | Promise对象。返回读取的结果。 |
666
667**错误码:**
668
669接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
670
671**示例:**
672
673  ```js
674  let filePath = pathDir + "/test.txt";
675  let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE);
676  let buf = new ArrayBuffer(4096);
677  fs.read(file.fd, buf).then((readLen) => {
678      console.info("read file data succeed");
679      console.info(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
680      fs.closeSync(file);
681  }).catch((err) => {
682      console.info("read file data failed with error message: " + err.message + ", error code: " + err.code);
683  });
684  ```
685
686## fs.read
687
688read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }, callback: AsyncCallback&lt;number&gt;): void
689
690从文件读取数据,使用callback异步回调。
691
692**系统能力**:SystemCapability.FileManagement.File.FileIO
693
694**参数:**
695
696  | 参数名      | 类型                                       | 必填   | 说明                                       |
697  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
698  | fd       | number                                   | 是    | 已打开的文件描述符。                             |
699  | buffer   | ArrayBuffer                              | 是    | 用于保存读取到的文件数据的缓冲区。                        |
700  | options | Object      | 否   | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度。|
701  | callback | AsyncCallback&lt;number&gt; | 是    | 异步读取数据之后的回调。                             |
702
703**错误码:**
704
705接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
706
707**示例:**
708
709  ```js
710  let filePath = pathDir + "/test.txt";
711  let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE);
712  let buf = new ArrayBuffer(4096);
713  fs.read(file.fd, buf, (err, readLen) => {
714    if (err) {
715      console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
716    } else {
717      console.info("read file data succeed");
718      console.info(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
719      fs.closeSync(file);
720    }
721  });
722  ```
723
724## fs.readSync
725
726readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): number
727
728以同步方法从文件读取数据。
729
730**系统能力**:SystemCapability.FileManagement.File.FileIO
731
732**参数:**
733
734  | 参数名     | 类型          | 必填   | 说明                                       |
735  | ------- | ----------- | ---- | ---------------------------------------- |
736  | fd      | number      | 是    | 已打开的文件描述符。                             |
737  | buffer  | ArrayBuffer | 是    | 用于保存读取到的文件数据的缓冲区。                        |
738  | options | Object      | 否   | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度。|
739
740**返回值:**
741
742  | 类型     | 说明       |
743  | ------ | -------- |
744  | number | 实际读取的长度。 |
745
746**错误码:**
747
748接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
749
750**示例:**
751
752  ```js
753  let filePath = pathDir + "/test.txt";
754  let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE);
755  let buf = new ArrayBuffer(4096);
756  let num = fs.readSync(file.fd, buf);
757  fs.closeSync(file);
758  ```
759
760## fs.rmdir
761
762rmdir(path: string): Promise&lt;void&gt;
763
764删除整个目录,使用Promise异步回调。
765
766**系统能力**:SystemCapability.FileManagement.File.FileIO
767
768**参数:**
769
770| 参数名 | 类型   | 必填 | 说明                       |
771| ------ | ------ | ---- | -------------------------- |
772| path   | string | 是   | 目录的应用沙箱路径。 |
773
774**返回值:**
775
776  | 类型                  | 说明                           |
777  | ------------------- | ---------------------------- |
778  | Promise&lt;void&gt; | Promise对象。无返回值。 |
779
780**错误码:**
781
782接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
783
784**示例:**
785
786  ```js
787  let dirPath = pathDir + "/testDir";
788  fs.rmdir(dirPath).then(() => {
789      console.info("rmdir succeed");
790  }).catch((err) => {
791      console.info("rmdir failed with error message: " + err.message + ", error code: " + err.code);
792  });
793  ```
794
795## fs.rmdir
796
797rmdir(path: string, callback: AsyncCallback&lt;void&gt;): void
798
799删除整个目录,使用callback异步回调。
800
801**系统能力**:SystemCapability.FileManagement.File.FileIO
802
803**参数:**
804
805| 参数名   | 类型                      | 必填 | 说明                       |
806| -------- | ------------------------- | ---- | -------------------------- |
807| path     | string                    | 是   | 目录的应用沙箱路径。 |
808| callback | AsyncCallback&lt;void&gt; | 是   | 异步删除目录之后的回调。   |
809
810**错误码:**
811
812接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
813
814**示例:**
815
816  ```js
817  let dirPath = pathDir + "/testDir";
818  fs.rmdir(dirPath, (err) => {
819    if (err) {
820      console.info("rmdir failed with error message: " + err.message + ", error code: " + err.code);
821    } else {
822      console.info("rmdir succeed");
823    }
824  });
825  ```
826
827## fs.rmdirSync
828
829rmdirSync(path: string): void
830
831以同步方法删除目录。
832
833**系统能力**:SystemCapability.FileManagement.File.FileIO
834
835**参数:**
836
837| 参数名 | 类型   | 必填 | 说明                       |
838| ------ | ------ | ---- | -------------------------- |
839| path   | string | 是   | 目录的应用沙箱路径。 |
840
841**错误码:**
842
843接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
844
845**示例:**
846
847  ```js
848  let dirPath = pathDir + "/testDir";
849  fs.rmdirSync(dirPath);
850  ```
851
852## fs.unlink
853
854unlink(path: string): Promise&lt;void&gt;
855
856删除单个文件,使用Promise异步回调。
857
858**系统能力**:SystemCapability.FileManagement.File.FileIO
859
860**参数:**
861
862| 参数名 | 类型   | 必填 | 说明                       |
863| ------ | ------ | ---- | -------------------------- |
864| path   | string | 是   | 文件的应用沙箱路径。 |
865
866**返回值:**
867
868  | 类型                  | 说明                           |
869  | ------------------- | ---------------------------- |
870  | Promise&lt;void&gt; | Promise对象。无返回值。 |
871
872**错误码:**
873
874接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
875
876**示例:**
877
878  ```js
879  let filePath = pathDir + "/test.txt";
880  fs.unlink(filePath).then(() => {
881      console.info("remove file succeed");
882  }).catch((err) => {
883      console.info("remove file failed with error message: " + err.message + ", error code: " + err.codeor);
884  });
885  ```
886
887## fs.unlink
888
889unlink(path: string, callback: AsyncCallback&lt;void&gt;): void
890
891删除文件,使用callback异步回调。
892
893**系统能力**:SystemCapability.FileManagement.File.FileIO
894
895**参数:**
896
897| 参数名   | 类型                      | 必填 | 说明                       |
898| -------- | ------------------------- | ---- | -------------------------- |
899| path     | string                    | 是   | 文件的应用沙箱路径。 |
900| callback | AsyncCallback&lt;void&gt; | 是   | 异步删除文件之后的回调。   |
901
902**错误码:**
903
904接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
905
906**示例:**
907
908  ```js
909  let filePath = pathDir + "/test.txt";
910  fs.unlink(filePath, (err) => {
911    if (err) {
912      console.info("remove file failed with error message: " + err.message + ", error code: " + err.code);
913    } else {
914      console.info("remove file succeed");
915    }
916  });
917  ```
918
919## fs.unlinkSync
920
921unlinkSync(path: string): void
922
923以同步方法删除文件。
924
925**系统能力**:SystemCapability.FileManagement.File.FileIO
926
927**参数:**
928
929| 参数名 | 类型   | 必填 | 说明                       |
930| ------ | ------ | ---- | -------------------------- |
931| path   | string | 是   | 文件的应用沙箱路径。 |
932
933**错误码:**
934
935接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
936
937**示例:**
938
939  ```js
940  let filePath = pathDir + "/test.txt";
941  fs.unlinkSync(filePath);
942  ```
943
944
945## fs.write
946
947write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }): Promise&lt;number&gt;
948
949将数据写入文件,使用Promise异步回调。
950
951**系统能力**:SystemCapability.FileManagement.File.FileIO
952
953**参数:**
954
955  | 参数名     | 类型                              | 必填   | 说明                                       |
956  | ------- | ------------------------------- | ---- | ---------------------------------------- |
957  | fd      | number                          | 是    | 已打开的文件描述符。                             |
958  | buffer  | ArrayBuffer\|string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
959  | options | Object                          | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。当前仅支持&nbsp;'utf-8'。|
960
961**返回值:**
962
963  | 类型                    | 说明       |
964  | --------------------- | -------- |
965  | Promise&lt;number&gt; | Promise对象。返回实际写入的长度。 |
966
967**错误码:**
968
969接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
970
971**示例:**
972
973  ```js
974  let filePath = pathDir + "/test.txt";
975  let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
976  fs.write(file.fd, "hello, world").then((writeLen) => {
977    console.info("write data to file succeed and size is:" + writeLen);
978    fs.closeSync(file);
979  }).catch((err) => {
980    console.info("write data to file failed with error message: " + err.message + ", error code: " + err.code);
981  });
982  ```
983
984## fs.write
985
986write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;number&gt;): void
987
988将数据写入文件,使用callback异步回调。
989
990**系统能力**:SystemCapability.FileManagement.File.FileIO
991
992**参数:**
993
994  | 参数名      | 类型                              | 必填   | 说明                                       |
995  | -------- | ------------------------------- | ---- | ---------------------------------------- |
996  | fd       | number                          | 是    | 已打开的文件描述符。                             |
997  | buffer   | ArrayBuffer\|string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
998  | options | Object                          | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。当前仅支持&nbsp;'utf-8'。|
999  | callback | AsyncCallback&lt;number&gt;     | 是    | 异步将数据写入完成后执行的回调函数。                       |
1000
1001**错误码:**
1002
1003接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1004
1005**示例:**
1006
1007  ```js
1008  let filePath = pathDir + "/test.txt";
1009  let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
1010  fs.write(file.fd, "hello, world", (err, writeLen) => {
1011    if (err) {
1012      console.info("write failed with error message: " + err.message + ", error code: " + err.code);
1013    } else {
1014      console.info("write data to file succeed and size is:" + writeLen);
1015      fs.closeSync(file);
1016    }
1017  });
1018  ```
1019
1020## fs.writeSync
1021
1022writeSync(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }): number
1023
1024以同步方法将数据写入文件。
1025
1026**系统能力**:SystemCapability.FileManagement.File.FileIO
1027
1028**参数:**
1029
1030  | 参数名     | 类型                              | 必填   | 说明                                       |
1031  | ------- | ------------------------------- | ---- | ---------------------------------------- |
1032  | fd      | number                          | 是    | 已打开的文件描述符。                             |
1033  | buffer  | ArrayBuffer\|string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
1034  | options | Object                          | 否    | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。当前仅支持&nbsp;'utf-8'。|
1035
1036**返回值:**
1037
1038  | 类型     | 说明       |
1039  | ------ | -------- |
1040  | number | 实际写入的长度。 |
1041
1042**错误码:**
1043
1044接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1045
1046**示例:**
1047
1048  ```js
1049  let filePath = pathDir + "/test.txt";
1050  let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
1051  let writeLen = fs.writeSync(file.fd, "hello, world");
1052  console.info("write data to file succeed and size is:" + writeLen);
1053  fs.closeSync(file);
1054  ```
1055
1056## fs.truncate
1057
1058truncate(file: string|number, len?: number): Promise&lt;void&gt;
1059
1060截断文件,使用Promise异步回调。
1061
1062**系统能力**:SystemCapability.FileManagement.File.FileIO
1063
1064**参数:**
1065
1066| 参数名 | 类型   | 必填 | 说明                             |
1067| ------ | ------ | ---- | -------------------------------- |
1068| file   | string\|number | 是   | 文件的应用沙箱路径或已打开的文件描述符fd。       |
1069| len    | number | 否   | 文件截断后的长度,以字节为单位。默认为0。 |
1070
1071**返回值:**
1072
1073  | 类型                  | 说明                           |
1074  | ------------------- | ---------------------------- |
1075  | Promise&lt;void&gt; | Promise对象。无返回值。 |
1076
1077**错误码:**
1078
1079接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1080
1081**示例:**
1082
1083  ```js
1084  let filePath = pathDir + "/test.txt";
1085  let len = 5;
1086  fs.truncate(filePath, len).then(() => {
1087      console.info("truncate file succeed");
1088  }).catch((err) => {
1089      console.info("truncate file failed with error message: " + err.message + ", error code: " + err.code);
1090  });
1091  ```
1092
1093## fs.truncate
1094
1095truncate(file: string|number, len?: number, callback: AsyncCallback&lt;void&gt;): void
1096
1097截断文件,使用callback异步回调。
1098
1099**系统能力**:SystemCapability.FileManagement.File.FileIO
1100
1101**参数:**
1102
1103| 参数名   | 类型                      | 必填 | 说明                             |
1104| -------- | ------------------------- | ---- | -------------------------------- |
1105| file     | string\|number                    | 是   | 文件的应用沙箱路径或已打开的文件描述符fd。       |
1106| len      | number                    | 否   | 文件截断后的长度,以字节为单位。默认为0。 |
1107| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数,本调用无返回值。   |
1108
1109**错误码:**
1110
1111接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1112
1113**示例:**
1114
1115  ```js
1116  let filePath = pathDir + "/test.txt";
1117  let len = 5;
1118  fs.truncate(filePath, len, (err) => {
1119    if (err) {
1120      console.info("truncate failed with error message: " + err.message + ", error code: " + err.code);
1121    } else {
1122      console.info("truncate success");
1123    }
1124  });
1125  ```
1126
1127## fs.truncateSync
1128
1129truncateSync(file: string|number, len?: number): void
1130
1131以同步方法截断文件。
1132
1133**系统能力**:SystemCapability.FileManagement.File.FileIO
1134
1135**参数:**
1136
1137| 参数名 | 类型   | 必填 | 说明                             |
1138| ------ | ------ | ---- | -------------------------------- |
1139| file   | string\|number | 是   | 文件的应用沙箱路径或已打开的文件描述符fd。       |
1140| len    | number | 否   | 文件截断后的长度,以字节为单位。默认为0。 |
1141
1142**错误码:**
1143
1144接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1145
1146**示例:**
1147
1148  ```js
1149  let filePath = pathDir + "/test.txt";
1150  let len = 5;
1151  fs.truncateSync(filePath, len);
1152  ```
1153
1154## fs.readText
1155
1156readText(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }): Promise&lt;string&gt;
1157
1158基于文本方式读取文件(即直接读取文件的文本内容),使用Promise异步回调。
1159
1160**系统能力**:SystemCapability.FileManagement.File.FileIO
1161
1162**参数:**
1163
1164| 参数名   | 类型   | 必填 | 说明                                                         |
1165| -------- | ------ | ---- | ------------------------------------------------------------ |
1166| filePath | string | 是   | 文件的应用沙箱路径。                                   |
1167| options  | Object | 否   | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认文件长度。<br/>-&nbsp;encoding,string类型,当数据是&nbsp;string&nbsp;类型时有效,表示数据的编码方式,默认&nbsp;'utf-8',仅支持&nbsp;'utf-8'。 |
1168
1169**返回值:**
1170
1171  | 类型                    | 说明         |
1172  | --------------------- | ---------- |
1173  | Promise&lt;string&gt; | Promise对象。返回读取文件的内容。 |
1174
1175**错误码:**
1176
1177接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1178
1179**示例:**
1180
1181  ```js
1182  let filePath = pathDir + "/test.txt";
1183  fs.readText(filePath).then((str) => {
1184      console.info("readText succeed:" + str);
1185  }).catch((err) => {
1186      console.info("readText failed with error message: " + err.message + ", error code: " + err.code);
1187  });
1188  ```
1189
1190## fs.readText
1191
1192readText(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;string&gt;): void
1193
1194基于文本方式读取文件(即直接读取文件的文本内容),使用callback异步回调。
1195
1196**系统能力**:SystemCapability.FileManagement.File.FileIO
1197
1198**参数:**
1199
1200| 参数名   | 类型                        | 必填 | 说明                                                         |
1201| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
1202| filePath | string                      | 是   | 文件的应用沙箱路径。                                   |
1203| options  | Object                      | 否   | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认文件长度。<br/>-&nbsp;encoding,string类型,表示数据的编码方式,默认&nbsp;'utf-8',仅支持&nbsp;'utf-8'。 |
1204| callback | AsyncCallback&lt;string&gt; | 是   | 回调函数,返回读取文件的内容。                         |
1205
1206**错误码:**
1207
1208接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1209
1210**示例:**
1211
1212  ```js
1213  let filePath = pathDir + "/test.txt";
1214  fs.readText(filePath, { offset: 1, encoding: 'UTF-8' }, (err, str) => {
1215    if (err) {
1216      console.info("read text failed with error message: " + err.message + ", error code: " + err.code);
1217    } else {
1218      console.info("readText succeed:" + str);
1219    }
1220  });
1221  ```
1222
1223## fs.readTextSync
1224
1225readTextSync(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }): string
1226
1227以同步方法基于文本方式读取文件(即直接读取文件的文本内容)。
1228
1229**系统能力**:SystemCapability.FileManagement.File.FileIO
1230
1231**参数:**
1232
1233| 参数名   | 类型   | 必填 | 说明                                                         |
1234| -------- | ------ | ---- | ------------------------------------------------------------ |
1235| filePath | string | 是   | 文件的应用沙箱路径。                                   |
1236| options  | Object | 否   | 支持如下选项:<br/>-&nbsp;offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认文件长度。<br/>-&nbsp;encoding,string类型,当数据是&nbsp;string&nbsp;类型时有效,表示数据的编码方式,默认&nbsp;'utf-8',仅支持&nbsp;'utf-8'。 |
1237
1238**返回值:**
1239
1240  | 类型   | 说明                 |
1241  | ------ | -------------------- |
1242  | string | 返回读取文件的内容。 |
1243
1244**错误码:**
1245
1246接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1247
1248**示例:**
1249
1250  ```js
1251  let filePath = pathDir + "/test.txt";
1252  let str = fs.readTextSync(filePath, {offset: 1, length: 3});
1253  console.info("readText succeed:" + str);
1254  ```
1255
1256## fs.lstat
1257
1258lstat(path: string): Promise&lt;Stat&gt;
1259
1260获取链接文件信息,使用Promise异步回调。
1261
1262**系统能力**:SystemCapability.FileManagement.File.FileIO
1263
1264**参数:**
1265
1266| 参数名 | 类型   | 必填 | 说明                                   |
1267| ------ | ------ | ---- | -------------------------------------- |
1268| path   | string | 是   | 文件的应用沙箱路径。 |
1269
1270**返回值:**
1271
1272  | 类型                           | 说明         |
1273  | ---------------------------- | ---------- |
1274  | Promise&lt;[Stat](#stat)&gt; | promise对象,返回文件对象,表示文件的具体信息,详情见stat。 |
1275
1276**错误码:**
1277
1278接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1279
1280**示例:**
1281
1282  ```js
1283  let filePath = pathDir + "/test.txt";
1284  fs.lstat(filePath).then((stat) => {
1285      console.info("get link status succeed, the size of file is" + stat.size);
1286  }).catch((err) => {
1287      console.info("get link status failed with error message: " + err.message + ", error code: " + err.code);
1288  });
1289  ```
1290
1291## fs.lstat
1292
1293lstat(path: string, callback: AsyncCallback&lt;Stat&gt;): void
1294
1295获取链接文件信息,使用callback异步回调。
1296
1297**系统能力**:SystemCapability.FileManagement.File.FileIO
1298
1299**参数:**
1300
1301| 参数名   | 类型                               | 必填 | 说明                                   |
1302| -------- | ---------------------------------- | ---- | -------------------------------------- |
1303| path     | string                             | 是   | 文件的应用沙箱路径。 |
1304| callback | AsyncCallback&lt;[Stat](#stat)&gt; | 是   | 回调函数,返回文件的具体信息。       |
1305
1306**错误码:**
1307
1308接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1309
1310**示例:**
1311
1312  ```js
1313  let filePath = pathDir + "/test.txt";
1314  fs.lstat(filePath, (err, stat) => {
1315      if (err) {
1316        console.info("lstat failed with error message: " + err.message + ", error code: " + err.code);
1317      } else {
1318        console.info("get link status succeed, the size of file is" + stat.size);
1319      }
1320  });
1321  ```
1322
1323## fs.lstatSync
1324
1325lstatSync(path: string): Stat
1326
1327以同步方法获取链接文件信息。
1328
1329**系统能力**:SystemCapability.FileManagement.File.FileIO
1330
1331**参数:**
1332
1333| 参数名 | 类型   | 必填 | 说明                                   |
1334| ------ | ------ | ---- | -------------------------------------- |
1335| path   | string | 是   | 文件的应用沙箱路径。 |
1336
1337**返回值:**
1338
1339  | 类型            | 说明         |
1340  | ------------- | ---------- |
1341  | [Stat](#stat) | 表示文件的具体信息。 |
1342
1343**错误码:**
1344
1345接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1346
1347**示例:**
1348
1349  ```js
1350  let filePath = pathDir + "/test.txt";
1351  let stat = fs.lstatSync(filePath);
1352  ```
1353
1354## fs.rename
1355
1356rename(oldPath: string, newPath: string): Promise&lt;void&gt;
1357
1358重命名文件或文件夹,使用Promise异步回调。
1359
1360**系统能力**:SystemCapability.FileManagement.File.FileIO
1361
1362**参数:**
1363
1364| 参数名  | 类型   | 必填 | 说明                         |
1365| ------- | ------ | ---- | ---------------------------- |
1366| oldPath | string | 是   | 文件的应用沙箱原路径。 |
1367| newPath | string | 是   | 文件的应用沙箱新路径。   |
1368
1369**返回值:**
1370
1371  | 类型                  | 说明                           |
1372  | ------------------- | ---------------------------- |
1373  | Promise&lt;void&gt; | Promise对象。无返回值。 |
1374
1375**错误码:**
1376
1377接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1378
1379**示例:**
1380
1381  ```js
1382  let srcFile = pathDir + "/test.txt";
1383  let dstFile = pathDir + "/new.txt";
1384  fs.rename(srcFile, dstFile).then(() => {
1385      console.info("rename succeed");
1386  }).catch((err) => {
1387      console.info("rename failed with error message: " + err.message + ", error code: " + err.code);
1388  });
1389  ```
1390
1391## fs.rename
1392
1393rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void
1394
1395重命名文件或文件夹,使用callback异步回调。
1396
1397**系统能力**:SystemCapability.FileManagement.File.FileIO
1398
1399**参数:**
1400
1401| 参数名   | 类型                      | 必填 | 说明                         |
1402| -------- | ------------------------- | ---- | ---------------------------- |
1403| oldPath | string | 是   | 文件的应用沙箱原路径。 |
1404| newPath | string | 是   | 文件的应用沙箱新路径。   |
1405| callback | AsyncCallback&lt;void&gt; | 是   | 异步重命名文件之后的回调。   |
1406
1407**错误码:**
1408
1409接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1410
1411**示例:**
1412
1413  ```js
1414  let srcFile = pathDir + "/test.txt";
1415  let dstFile = pathDir + "/new.txt";
1416  fs.rename(srcFile, dstFile, (err) => {
1417    if (err) {
1418      console.info("rename failed with error message: " + err.message + ", error code: " + err.code);
1419    } else {
1420      console.info("rename success");
1421    }
1422  });
1423  ```
1424
1425## fs.renameSync
1426
1427renameSync(oldPath: string, newPath: string): void
1428
1429以同步方法重命名文件或文件夹。
1430
1431**系统能力**:SystemCapability.FileManagement.File.FileIO
1432
1433**参数:**
1434
1435| 参数名  | 类型   | 必填 | 说明                         |
1436| ------- | ------ | ---- | ---------------------------- |
1437| oldPath | string | 是   | 文件的应用沙箱原路径。 |
1438| newPath | string | 是   | 文件的应用沙箱新路径。   |
1439
1440**错误码:**
1441
1442接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1443
1444**示例:**
1445
1446  ```js
1447  let srcFile = pathDir + "/test.txt";
1448  let dstFile = pathDir + "/new.txt";
1449  fs.renameSync(srcFile, dstFile);
1450  ```
1451
1452## fs.fsync
1453
1454fsync(fd: number): Promise&lt;void&gt;
1455
1456同步文件数据,使用Promise异步回调。
1457
1458**系统能力**:SystemCapability.FileManagement.File.FileIO
1459
1460**参数:**
1461
1462  | 参数名  | 类型     | 必填   | 说明           |
1463  | ---- | ------ | ---- | ------------ |
1464  | fd   | number | 是    | 已打开的文件描述符。 |
1465
1466**返回值:**
1467
1468  | 类型                  | 说明                           |
1469  | ------------------- | ---------------------------- |
1470  | Promise&lt;void&gt; | Promise对象。无返回值。 |
1471
1472**错误码:**
1473
1474接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1475
1476**示例:**
1477
1478  ```js
1479  let filePath = pathDir + "/test.txt";
1480  let file = fs.openSync(filePath);
1481  fs.fsync(file.fd).then(() => {
1482      console.info("sync data succeed");
1483  }).catch((err) => {
1484      console.info("sync data failed with error message: " + err.message + ", error code: " + err.code);
1485  });
1486  ```
1487
1488## fs.fsync
1489
1490fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void
1491
1492同步文件数据,使用callback异步回调。
1493
1494**系统能力**:SystemCapability.FileManagement.File.FileIO
1495
1496**参数:**
1497
1498  | 参数名      | 类型                        | 必填   | 说明              |
1499  | -------- | ------------------------- | ---- | --------------- |
1500  | fd       | number                    | 是    | 已打开的文件描述符。    |
1501  | Callback | AsyncCallback&lt;void&gt; | 是    | 异步将文件数据同步之后的回调。 |
1502
1503**错误码:**
1504
1505接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1506
1507**示例:**
1508
1509  ```js
1510  let filePath = pathDir + "/test.txt";
1511  let file = fs.openSync(filePath);
1512  fs.fsync(file.fd, (err) => {
1513    if (err) {
1514      console.info("fsync failed with error message: " + err.message + ", error code: " + err.code);
1515    } else {
1516      console.info("fsync success");
1517      fs.closeSync(file);
1518    }
1519  });
1520  ```
1521
1522
1523## fs.fsyncSync
1524
1525fsyncSync(fd: number): void
1526
1527以同步方法同步文件数据。
1528
1529**系统能力**:SystemCapability.FileManagement.File.FileIO
1530
1531**参数:**
1532
1533  | 参数名  | 类型     | 必填   | 说明           |
1534  | ---- | ------ | ---- | ------------ |
1535  | fd   | number | 是    | 已打开的文件描述符。 |
1536
1537**错误码:**
1538
1539接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1540
1541**示例:**
1542
1543  ```js
1544  let filePath = pathDir + "/test.txt";
1545  let file = fs.openSync(filePath);
1546  fs.fsyncSync(file.fd);
1547  fs.closeSync(file);
1548  ```
1549
1550## fs.fdatasync
1551
1552fdatasync(fd: number): Promise&lt;void&gt;
1553
1554实现文件内容数据同步,使用Promise异步回调。
1555
1556**系统能力**:SystemCapability.FileManagement.File.FileIO
1557
1558**参数:**
1559
1560  | 参数名  | 类型     | 必填   | 说明           |
1561  | ---- | ------ | ---- | ------------ |
1562  | fd   | number | 是    | 已打开的文件描述符。 |
1563
1564**返回值:**
1565
1566  | 类型                  | 说明                           |
1567  | ------------------- | ---------------------------- |
1568  | Promise&lt;void&gt; | Promise对象。无返回值。 |
1569
1570**错误码:**
1571
1572接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1573
1574**示例:**
1575
1576  ```js
1577  let filePath = pathDir + "/test.txt";
1578  let file = fs.openSync(filePath);
1579  fs.fdatasync(file.fd).then((err) => {
1580    console.info("sync data succeed");
1581    fs.closeSync(file);
1582  }).catch((err) => {
1583    console.info("sync data failed with error message: " + err.message + ", error code: " + err.code);
1584  });
1585  ```
1586
1587## fs.fdatasync
1588
1589fdatasync(fd: number, callback: AsyncCallback&lt;void&gt;): void
1590
1591实现文件内容数据同步,使用callback异步回调。
1592
1593**系统能力**:SystemCapability.FileManagement.File.FileIO
1594
1595**参数:**
1596
1597  | 参数名      | 类型                              | 必填   | 说明                |
1598  | -------- | ------------------------------- | ---- | ----------------- |
1599  | fd       | number                          | 是    | 已打开的文件描述符。      |
1600  | callback | AsyncCallback&lt;void&gt; | 是    | 异步将文件内容数据同步之后的回调。 |
1601
1602**错误码:**
1603
1604接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1605
1606**示例:**
1607
1608  ```js
1609  let filePath = pathDir + "/test.txt";
1610  let file = fs.openSync(filePath);
1611  fs.fdatasync (file.fd, (err) => {
1612    if (err) {
1613      console.info("fdatasync failed with error message: " + err.message + ", error code: " + err.code);
1614    } else {
1615      console.info("fdatasync success");
1616      fs.closeSync(file);
1617    }
1618  });
1619  ```
1620
1621## fs.fdatasyncSync
1622
1623fdatasyncSync(fd: number): void
1624
1625以同步方法实现文件内容数据同步。
1626
1627**系统能力**:SystemCapability.FileManagement.File.FileIO
1628
1629**参数:**
1630
1631  | 参数名  | 类型     | 必填   | 说明           |
1632  | ---- | ------ | ---- | ------------ |
1633  | fd   | number | 是    | 已打开的文件描述符。 |
1634
1635**错误码:**
1636
1637接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1638
1639**示例:**
1640
1641  ```js
1642  let filePath = pathDir + "/test.txt";
1643  let file = fs.openSync(filePath);
1644  let stat = fs.fdatasyncSync(file.fd);
1645  fs.closeSync(file);
1646  ```
1647
1648## fs.symlink
1649
1650symlink(target: string, srcPath: string): Promise&lt;void&gt;
1651
1652基于文件路径创建符号链接,使用Promise异步回调。
1653
1654**系统能力**:SystemCapability.FileManagement.File.FileIO
1655
1656**参数:**
1657
1658| 参数名  | 类型   | 必填 | 说明                         |
1659| ------- | ------ | ---- | ---------------------------- |
1660| target  | string | 是   | 源文件的应用沙箱路径。     |
1661| srcPath | string | 是   | 符号链接文件的应用沙箱路径。 |
1662
1663**返回值:**
1664
1665  | 类型                  | 说明                           |
1666  | ------------------- | ---------------------------- |
1667  | Promise&lt;void&gt; | Promise对象。无返回值。 |
1668
1669**错误码:**
1670
1671接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1672
1673**示例:**
1674
1675  ```js
1676  let srcFile = pathDir + "/test.txt";
1677  let dstFile = pathDir + "/test";
1678  fs.symlink(srcFile, dstFile).then(() => {
1679      console.info("symlink succeed");
1680  }).catch((err) => {
1681      console.info("symlink failed with error message: " + err.message + ", error code: " + err.code);
1682  });
1683  ```
1684
1685
1686## fs.symlink
1687symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): void
1688
1689基于文件路径创建符号链接,使用callback异步回调。
1690
1691**系统能力**:SystemCapability.FileManagement.File.FileIO
1692
1693**参数:**
1694
1695| 参数名   | 类型                      | 必填 | 说明                             |
1696| -------- | ------------------------- | ---- | -------------------------------- |
1697| target   | string                    | 是   | 源文件的应用沙箱路径。         |
1698| srcPath  | string                    | 是   | 符号链接文件的应用沙箱路径。     |
1699| callback | AsyncCallback&lt;void&gt; | 是   | 异步创建符号链接信息之后的回调。 |
1700
1701**错误码:**
1702
1703接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1704
1705**示例:**
1706
1707  ```js
1708  let srcFile = pathDir + "/test.txt";
1709  let dstFile = pathDir + "/test";
1710  fs.symlink(srcFile, dstFile, (err) => {
1711    if (err) {
1712      console.info("symlink failed with error message: " + err.message + ", error code: " + err.code);
1713    } else {
1714      console.info("symlink success");
1715    }
1716  });
1717  ```
1718
1719## fs.symlinkSync
1720
1721symlinkSync(target: string, srcPath: string): void
1722
1723以同步的方法基于文件路径创建符号链接。
1724
1725**系统能力**:SystemCapability.FileManagement.File.FileIO
1726
1727**参数:**
1728
1729| 参数名  | 类型   | 必填 | 说明                         |
1730| ------- | ------ | ---- | ---------------------------- |
1731| target  | string | 是   | 源文件的应用沙箱路径。     |
1732| srcPath | string | 是   | 符号链接文件的应用沙箱路径。 |
1733
1734**错误码:**
1735
1736接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1737
1738**示例:**
1739
1740  ```js
1741  let srcFile = pathDir + "/test.txt";
1742  let dstFile = pathDir + "/test";
1743  fs.symlinkSync(srcFile, dstFile);
1744  ```
1745
1746## fs.listFile
1747listFile(path: string, options?: {
1748    recursion?: boolean;
1749    listNum?: number;
1750    filter?: Filter;
1751}): Promise<string[]>
1752
1753列出文件夹下所有文件名,支持递归列出所有文件名(包含子目录下),支持文件过滤,使用Promise异步回调。
1754
1755**系统能力**:SystemCapability.FileManagement.File.FileIO
1756
1757**参数:**
1758
1759  | 参数名    | 类型     | 必填   | 说明                          |
1760  | ------ | ------ | ---- | --------------------------- |
1761  | path | string | 是    | 文件夹的应用沙箱路径。 |
1762  | options | Object | 否    | 文件过滤选项。默认不进行过滤。 |
1763
1764**options参数说明:**
1765
1766  | 参数名    | 类型     | 必填   | 说明                          |
1767  | ------ | ------ | ---- | --------------------------- |
1768  | recursion | boolean | 否    | 是否递归子目录下文件名,默认为false。 |
1769  | listNum | number | 否    | 列出文件名数量。当设置0时,列出所有文件,默认为0。 |
1770  | filter | [Filter](#filter) | 否    | 文件过滤选项。当前仅支持后缀名匹配、文件名模糊查询、文件大小过滤、最近修改时间过滤。 |
1771
1772**返回值:**
1773
1774  | 类型                   | 说明         |
1775  | --------------------- | ---------- |
1776  | Promise&lt;string[]&gt; | Promise对象。返回文件名数组。 |
1777
1778**错误码:**
1779
1780接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1781
1782**示例:**
1783
1784  ```js
1785  let options = {
1786    "recursion": false,
1787    "listNum": 0,
1788    "filter": {
1789      "suffix": [".png", ".jpg", ".jpeg"],
1790      "displayName": ["%abc", "efg%"],
1791      "fileSizeOver": 1024,
1792      "lastModifiedAfter": new Date().getTime(),
1793    }
1794  };
1795  fs.listFile(pathDir, options).then((filenames) => {
1796    console.info("listFile succeed");
1797    for (let i = 0; i < filenames.length; i++) {
1798      console.info("fileName: %s", filenames[i]);
1799    }
1800  }).catch((err) => {
1801      console.info("list file failed with error message: " + err.message + ", error code: " + err.code);
1802  });
1803  ```
1804
1805## fs.listFile
1806listFile(path: string, options?: {
1807    recursion?: boolean;
1808    listNum?: number;
1809    filter?: Filter;
1810}, callback: AsyncCallback<string[]>): void
1811
1812列出文件夹下所有文件名,支持递归列出所有文件名(包含子目录下),支持文件过滤,使用Callback异步回调。
1813
1814**系统能力**:SystemCapability.FileManagement.File.FileIO
1815
1816**参数:**
1817
1818  | 参数名    | 类型     | 必填   | 说明                          |
1819  | ------ | ------ | ---- | --------------------------- |
1820  | path | string | 是    | 文件夹的应用沙箱路径。 |
1821  | options | Object | 否    | 文件过滤选项。默认不进行过滤。 |
1822  | callback | AsyncCallback&lt;string[]&gt; | 是    | 异步列出文件名数组之后的回调。              |
1823
1824**options参数说明:**
1825
1826  | 参数名    | 类型     | 必填   | 说明                          |
1827  | ------ | ------ | ---- | --------------------------- |
1828  | recursion | boolean | 否    | 是否递归子目录下文件名,默认为false。 |
1829  | listNum | number | 否    | 列出文件名数量。当设置0时,列出所有文件,默认为0。 |
1830  | filter | [Filter](#filter) | 否    | 文件过滤选项。当前仅支持后缀名匹配、文件名模糊查询、文件大小过滤、最近修改时间过滤。 |
1831
1832**错误码:**
1833
1834接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1835
1836**示例:**
1837
1838  ```js
1839  let options = {
1840    "recursion": false,
1841    "listNum": 0,
1842    "filter": {
1843      "suffix": [".png", ".jpg", ".jpeg"],
1844      "displayName": ["%abc", "efg%"],
1845      "fileSizeOver": 1024,
1846      "lastModifiedAfter": new Date().getTime(),
1847    }
1848  };
1849  fs.listFile(pathDir, options, (err, filenames) => {
1850    if (err) {
1851      console.info("list file failed with error message: " + err.message + ", error code: " + err.code);
1852    } else {
1853      console.info("listFile succeed");
1854      for (let i = 0; i < filenames.length; i++) {
1855        console.info("filename: %s", filenames[i]);
1856      }
1857    }
1858  });
1859  ```
1860
1861## fs.listFileSync
1862
1863listFileSync(path: string, options?: {
1864    recursion?: boolean;
1865    listNum?: number;
1866    filter?: Filter;
1867}): string[]
1868
1869以同步方式列出文件夹下所有文件名,支持递归列出所有文件名(包含子目录下),支持文件过滤。
1870
1871**系统能力**:SystemCapability.FileManagement.File.FileIO
1872
1873**参数:**
1874
1875  | 参数名    | 类型     | 必填   | 说明                          |
1876  | ------ | ------ | ---- | --------------------------- |
1877  | path | string | 是    | 文件夹的应用沙箱路径。 |
1878  | options | Object | 否    | 文件过滤选项。默认不进行过滤。 |
1879
1880**options参数说明:**
1881
1882  | 参数名    | 类型     | 必填   | 说明                          |
1883  | ------ | ------ | ---- | --------------------------- |
1884  | recursion | boolean | 否    | 是否递归子目录下文件名,默认为false。 |
1885  | listNum | number | 否    | 列出文件名数量。当设置0时,列出所有文件,默认为0。 |
1886  | filter | [Filter](#filter) | 否    | 文件过滤选项。当前仅支持后缀名匹配、文件名模糊查询、文件大小过滤、最近修改时间过滤。 |
1887
1888**返回值:**
1889
1890  | 类型                   | 说明         |
1891  | --------------------- | ---------- |
1892  | string[] | 返回文件名数组。 |
1893
1894**错误码:**
1895
1896接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1897
1898**示例:**
1899
1900  ```js
1901  let options = {
1902    "recursion": false,
1903    "listNum": 0,
1904    "filter": {
1905      "suffix": [".png", ".jpg", ".jpeg"],
1906      "displayName": ["%abc", "efg%"],
1907      "fileSizeOver": 1024,
1908      "lastModifiedAfter": new Date().getTime(),
1909    }
1910  };
1911  let filenames = fs.listFileSync(pathDir, options);
1912  console.info("listFile succeed");
1913  for (let i = 0; i < filenames.length; i++) {
1914    console.info("filename: %s", filenames[i]);
1915  }
1916  ```
1917
1918## fs.moveFile
1919
1920moveFile(src: string, dest: string, mode?: number): Promise\<void>
1921
1922移动文件,使用Promise异步回调。
1923
1924**系统能力**:SystemCapability.FileManagement.File.FileIO
1925
1926**参数:**
1927
1928  | 参数名    | 类型     | 必填   | 说明                          |
1929  | ------ | ------ | ---- | --------------------------- |
1930  | src | string | 是    | 源文件的应用沙箱路径。 |
1931  | dest | string | 是    | 目的文件的应用沙箱路径。 |
1932  | mode | number | 否    | 移动模式。若mode为0,移动位置存在同名文件时,强制移动覆盖。若mode为1,移动位置存在同名文件时,抛出异常。默认为0。 |
1933
1934**返回值:**
1935
1936  | 类型                  | 说明                           |
1937  | ------------------- | ---------------------------- |
1938  | Promise&lt;void&gt; | Promise对象。无返回值。 |
1939
1940**错误码:**
1941
1942接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1943
1944**示例:**
1945
1946  ```js
1947  let srcPath = pathDir + "/source.txt";
1948  let destPath = pathDir + "/dest.txt";
1949  fs.moveFile(srcPath, destPath, 0).then(() => {
1950      console.info("move file succeed");
1951  }).catch((err) => {
1952      console.info("move file failed with error message: " + err.message + ", error code: " + err.code);
1953  });
1954  ```
1955
1956## fs.moveFile
1957
1958moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback\<void>): void
1959
1960移动文件,使用Callback异步回调。
1961
1962**系统能力**:SystemCapability.FileManagement.File.FileIO
1963
1964**参数:**
1965
1966  | 参数名    | 类型     | 必填   | 说明                          |
1967  | ------ | ------ | ---- | --------------------------- |
1968  | src | string | 是    | 源文件的应用沙箱路径。 |
1969  | dest | string | 是    | 目的文件的应用沙箱路径。 |
1970  | mode | number | 否    | 移动模式。若mode为0,移动位置存在同名文件时,强制移动覆盖。若mode为1,移动位置存在同名文件时,抛出异常。默认为0。 |
1971  | callback | AsyncCallback&lt;void&gt; | 是    | 异步移动文件之后的回调。              |
1972
1973**错误码:**
1974
1975接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
1976
1977**示例:**
1978
1979  ```js
1980  let srcPath = pathDir + "/source.txt";
1981  let destPath = pathDir + "/dest.txt";
1982  fs.moveFile(srcPath, destPath, 0, (err) => {
1983    if (err) {
1984      console.info("move file failed with error message: " + err.message + ", error code: " + err.code);
1985    } else {
1986      console.info("move file succeed");
1987    }
1988  });
1989  ```
1990
1991## fs.moveFileSync
1992
1993moveFileSync(src: string, dest: string, mode?: number): void
1994
1995以同步方式移动文件。
1996
1997**系统能力**:SystemCapability.FileManagement.File.FileIO
1998
1999**参数:**
2000
2001  | 参数名    | 类型     | 必填   | 说明                          |
2002  | ------ | ------ | ---- | --------------------------- |
2003  | src | string | 是    | 源文件的应用沙箱路径。 |
2004  | dest | string | 是    | 目的文件的应用沙箱路径。 |
2005  | mode | number | 否    | 移动模式。若mode为0,移动位置存在同名文件时,强制移动覆盖。若mode为1,移动位置存在同名文件时,抛出异常。默认为0。 |
2006
2007**错误码:**
2008
2009接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2010
2011**示例:**
2012
2013  ```js
2014  let srcPath = pathDir + "/source.txt";
2015  let destPath = pathDir + "/dest.txt";
2016  fs.moveFileSync(srcPath, destPath, 0);
2017  console.info("move file succeed");
2018  ```
2019
2020## fs.mkdtemp
2021
2022mkdtemp(prefix: string): Promise&lt;string&gt;
2023
2024创建临时目录,使用Promise异步回调。
2025
2026**系统能力**:SystemCapability.FileManagement.File.FileIO
2027
2028**参数:**
2029
2030  | 参数名    | 类型     | 必填   | 说明                          |
2031  | ------ | ------ | ---- | --------------------------- |
2032  | prefix | string | 是    | 用随机产生的字符串替换以“XXXXXX”结尾目录路径。 |
2033
2034**返回值:**
2035
2036  | 类型                   | 说明         |
2037  | --------------------- | ---------- |
2038  | Promise&lt;string&gt; | Promise对象。返回生成的唯一目录路径。 |
2039
2040**错误码:**
2041
2042接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2043
2044**示例:**
2045
2046  ```js
2047  fs.mkdtemp(pathDir + "/XXXXXX").then((pathDir) => {
2048      console.info("mkdtemp succeed:" + pathDir);
2049  }).catch((err) => {
2050      console.info("mkdtemp failed with error message: " + err.message + ", error code: " + err.code);
2051  });
2052  ```
2053
2054## fs.mkdtemp
2055
2056mkdtemp(prefix: string, callback: AsyncCallback&lt;string&gt;): void
2057
2058创建临时目录,使用callback异步回调。
2059
2060**系统能力**:SystemCapability.FileManagement.File.FileIO
2061
2062**参数:**
2063
2064  | 参数名      | 类型                          | 必填   | 说明                          |
2065  | -------- | --------------------------- | ---- | --------------------------- |
2066  | prefix   | string                      | 是    | 用随机产生的字符串替换以“XXXXXX”结尾目录路径。 |
2067  | callback | AsyncCallback&lt;string&gt; | 是    | 异步创建临时目录之后的回调。              |
2068
2069**错误码:**
2070
2071接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2072
2073**示例:**
2074
2075  ```js
2076  fs.mkdtemp(pathDir + "/XXXXXX", (err, res) => {
2077    if (err) {
2078      console.info("mkdtemp failed with error message: " + err.message + ", error code: " + err.code);
2079    } else {
2080      console.info("mkdtemp success");
2081    }
2082  });
2083  ```
2084
2085## fs.mkdtempSync
2086
2087mkdtempSync(prefix: string): string
2088
2089以同步的方法创建临时目录。
2090
2091**系统能力**:SystemCapability.FileManagement.File.FileIO
2092
2093**参数:**
2094
2095  | 参数名    | 类型     | 必填   | 说明                          |
2096  | ------ | ------ | ---- | --------------------------- |
2097  | prefix | string | 是    | 用随机产生的字符串替换以“XXXXXX”结尾目录路径。 |
2098
2099**返回值:**
2100
2101  | 类型    | 说明         |
2102  | ------ | ---------- |
2103  | string | 产生的唯一目录路径。 |
2104
2105**错误码:**
2106
2107接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2108
2109**示例:**
2110
2111  ```js
2112  let res = fs.mkdtempSync(pathDir + "/XXXXXX");
2113  ```
2114
2115## fs.createStream
2116
2117createStream(path: string, mode: string): Promise&lt;Stream&gt;
2118
2119基于文件路径打开文件流,使用Promise异步回调。
2120
2121**系统能力**:SystemCapability.FileManagement.File.FileIO
2122
2123**参数:**
2124
2125| 参数名 | 类型   | 必填 | 说明                                                         |
2126| ------ | ------ | ---- | ------------------------------------------------------------ |
2127| path   | string | 是   | 文件的应用沙箱路径。                                   |
2128| mode   | string | 是   | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
2129
2130**返回值:**
2131
2132  | 类型                                | 说明        |
2133  | --------------------------------- | --------- |
2134  | Promise&lt;[Stream](#stream)&gt; | Promise对象。返回文件流的结果。 |
2135
2136**错误码:**
2137
2138接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2139
2140**示例:**
2141
2142  ```js
2143  let filePath = pathDir + "/test.txt";
2144  fs.createStream(filePath, "r+").then((stream) => {
2145      console.info("createStream succeed");
2146  }).catch((err) => {
2147      console.info("createStream failed with error message: " + err.message + ", error code: " + err.code);
2148  });
2149  ```
2150
2151
2152## fs.createStream
2153
2154createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
2155
2156基于文件路径打开文件流,使用callback异步回调。
2157
2158**系统能力**:SystemCapability.FileManagement.File.FileIO
2159
2160**参数:**
2161
2162| 参数名   | 类型                                    | 必填 | 说明                                                         |
2163| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
2164| path     | string                                  | 是   | 文件的应用沙箱路径。                                   |
2165| mode     | string                                  | 是   | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
2166| callback | AsyncCallback&lt;[Stream](#stream)&gt; | 是   | 异步打开文件流之后的回调。                                   |
2167
2168**错误码:**
2169
2170接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2171
2172**示例:**
2173
2174  ```js
2175  let filePath = pathDir + "/test.txt";
2176  fs.createStream(filePath, "r+", (err, stream) => {
2177    if (err) {
2178      console.info("create stream failed with error message: " + err.message + ", error code: " + err.code);
2179    } else {
2180      console.info("create stream success");
2181    }
2182  });
2183  ```
2184
2185## fs.createStreamSync
2186
2187createStreamSync(path: string, mode: string): Stream
2188
2189以同步方法基于文件路径打开文件流。
2190
2191**系统能力**:SystemCapability.FileManagement.File.FileIO
2192
2193**参数:**
2194
2195| 参数名 | 类型   | 必填 | 说明                                                         |
2196| ------ | ------ | ---- | ------------------------------------------------------------ |
2197| path   | string | 是   | 文件的应用沙箱路径。                                   |
2198| mode   | string | 是   | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
2199
2200**返回值:**
2201
2202  | 类型                | 说明        |
2203  | ------------------ | --------- |
2204  | [Stream](#stream) | 返回文件流的结果。 |
2205
2206**错误码:**
2207
2208接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2209
2210**示例:**
2211
2212  ```js
2213  let filePath = pathDir + "/test.txt";
2214  let ss = fs.createStreamSync(filePath, "r+");
2215  ```
2216
2217
2218## fs.fdopenStream
2219
2220fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;
2221
2222基于文件描述符打开文件流,使用Promise异步回调。
2223
2224**系统能力**:SystemCapability.FileManagement.File.FileIO
2225
2226**参数:**
2227
2228  | 参数名  | 类型     | 必填   | 说明                                       |
2229  | ---- | ------ | ---- | ---------------------------------------- |
2230  | fd   | number | 是    | 已打开的文件描述符。                             |
2231  | mode | string | 是    | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
2232
2233**返回值:**
2234
2235  | 类型                               | 说明        |
2236  | --------------------------------- | --------- |
2237  | Promise&lt;[Stream](#stream)&gt; | Promise对象。返回文件流的结果。 |
2238
2239**错误码:**
2240
2241接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2242
2243**示例:**
2244
2245  ```js
2246  let filePath = pathDir + "/test.txt";
2247  let file = fs.openSync(filePath);
2248  fs.fdopenStream(file.fd, "r+").then((stream) => {
2249      console.info("openStream succeed");
2250      fs.closeSync(file);
2251  }).catch((err) => {
2252      console.info("openStream failed with error message: " + err.message + ", error code: " + err.code);
2253  });
2254  ```
2255
2256## fs.fdopenStream
2257
2258fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
2259
2260基于文件描述符打开文件流,使用callback异步回调。
2261
2262**系统能力**:SystemCapability.FileManagement.File.FileIO
2263
2264**参数:**
2265
2266  | 参数名      | 类型                                       | 必填   | 说明                                       |
2267  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2268  | fd       | number                                   | 是    | 已打开的文件描述符。                             |
2269  | mode     | string                                   | 是    | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
2270  | callback | AsyncCallback&lt;[Stream](#stream)&gt; | 是    | 异步打开文件流之后的回调。                            |
2271
2272**错误码:**
2273
2274接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2275
2276**示例:**
2277
2278  ```js
2279  let filePath = pathDir + "/test.txt";
2280  let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
2281  fs.fdopenStream(file.fd, "r+", (err, stream) => {
2282    if (err) {
2283      console.info("fdopen stream failed with error message: " + err.message + ", error code: " + err.code);
2284    } else {
2285      console.info("fdopen stream success");
2286      fs.closeSync(file);
2287    }
2288  });
2289  ```
2290
2291## fs.fdopenStreamSync
2292
2293fdopenStreamSync(fd: number, mode: string): Stream
2294
2295以同步方法基于文件描述符打开文件流。
2296
2297**系统能力**:SystemCapability.FileManagement.File.FileIO
2298
2299**参数:**
2300
2301  | 参数名  | 类型     | 必填   | 说明                                       |
2302  | ---- | ------ | ---- | ---------------------------------------- |
2303  | fd   | number | 是    | 已打开的文件描述符。                             |
2304  | mode | string | 是    | -&nbsp;r:打开只读文件,该文件必须存在。<br/>-&nbsp;r+:打开可读写的文件,该文件必须存在。<br/>-&nbsp;w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。<br/>-&nbsp;a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。<br/>-&nbsp;a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 |
2305
2306**返回值:**
2307
2308  | 类型                | 说明        |
2309  | ------------------ | --------- |
2310  | [Stream](#stream) | 返回文件流的结果。 |
2311
2312**错误码:**
2313
2314接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2315
2316**示例:**
2317
2318  ```js
2319  let filePath = pathDir + "/test.txt";
2320  let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY | fs.OpenMode.CREATE);
2321  let ss = fs.fdopenStreamSync(file.fd, "r+");
2322  fs.closeSync(file);
2323  ```
2324
2325## Stat
2326
2327文件具体信息,在调用Stat的方法前,需要先通过[stat()](#fsstat)方法(同步或异步)来构建一个Stat实例。
2328
2329**系统能力**:SystemCapability.FileManagement.File.FileIO
2330
2331### 属性
2332
2333| 名称     | 类型   | 可读   | 可写   | 说明                                       |
2334| ------ | ------ | ---- | ---- | ---------------------------------------- |
2335| ino    | number | 是    | 否    | 标识该文件。通常同设备上的不同文件的INO不同。|                 |
2336| mode   | number | 是    | 否    | 表示文件权限,各特征位的含义如下:<br/>-&nbsp;0o400:用户读,对于普通文件,所有者可读取文件;对于目录,所有者可读取目录项。<br/>-&nbsp;0o200:用户写,对于普通文件,所有者可写入文件;对于目录,所有者可创建/删除目录项。<br/>-&nbsp;0o100:用户执行,对于普通文件,所有者可执行文件;对于目录,所有者可在目录中搜索给定路径名。<br/>-&nbsp;0o040:用户组读,对于普通文件,所有用户组可读取文件;对于目录,所有用户组可读取目录项。<br/>-&nbsp;0o020:用户组写,对于普通文件,所有用户组可写入文件;对于目录,所有用户组可创建/删除目录项。<br/>-&nbsp;0o010:用户组执行,对于普通文件,所有用户组可执行文件;对于目录,所有用户组是否可在目录中搜索给定路径名。<br/>-&nbsp;0o004:其他读,对于普通文件,其余用户可读取文件;对于目录,其他用户组可读取目录项。<br/>-&nbsp;0o002:其他写,对于普通文件,其余用户可写入文件;对于目录,其他用户组可创建/删除目录项。<br/>-&nbsp;0o001:其他执行,对于普通文件,其余用户可执行文件;对于目录,其他用户组可在目录中搜索给定路径名。 |
2337| uid    | number | 是    | 否    | 文件所有者的ID。|
2338| gid    | number | 是    | 否    | 文件所有组的ID。|
2339| size   | number | 是    | 否    | 文件的大小,以字节为单位。仅对普通文件有效。  |
2340| atime  | number | 是    | 否    | 上次访问该文件的时间,表示距1970年1月1日0时0分0秒的秒数。        |
2341| mtime  | number | 是    | 否    | 上次修改该文件的时间,表示距1970年1月1日0时0分0秒的秒数。        |
2342| ctime  | number | 是    | 否    | 最近改变文件状态的时间,表示距1970年1月1日0时0分0秒的秒数。      |
2343
2344### isBlockDevice
2345
2346isBlockDevice(): boolean
2347
2348用于判断文件是否是块特殊文件。一个块特殊文件只能以块为粒度进行访问,且访问的时候带缓存。
2349
2350**系统能力**:SystemCapability.FileManagement.File.FileIO
2351
2352**返回值:**
2353
2354  | 类型      | 说明               |
2355  | ------- | ---------------- |
2356  | boolean | 表示文件是否是块特殊设备。 |
2357
2358**错误码:**
2359
2360接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2361
2362**示例:**
2363
2364  ```js
2365  let filePath = pathDir + "/test.txt";
2366  let isBLockDevice = fs.statSync(filePath).isBlockDevice();
2367  ```
2368
2369### isCharacterDevice
2370
2371isCharacterDevice(): boolean
2372
2373用于判断文件是否是字符特殊文件。一个字符特殊设备可进行随机访问,且访问的时候不带缓存。
2374
2375**系统能力**:SystemCapability.FileManagement.File.FileIO
2376
2377**返回值:**
2378
2379  | 类型      | 说明                |
2380  | ------- | ----------------- |
2381  | boolean | 表示文件是否是字符特殊设备。 |
2382
2383**错误码:**
2384
2385接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2386
2387**示例:**
2388
2389  ```js
2390  let filePath = pathDir + "/test.txt";
2391  let isCharacterDevice = fs.statSync(filePath).isCharacterDevice();
2392  ```
2393
2394### isDirectory
2395
2396isDirectory(): boolean
2397
2398用于判断文件是否是目录。
2399
2400**系统能力**:SystemCapability.FileManagement.File.FileIO
2401
2402**返回值:**
2403
2404  | 类型      | 说明            |
2405  | ------- | ------------- |
2406  | boolean | 表示文件是否是目录。 |
2407
2408**错误码:**
2409
2410接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2411
2412**示例:**
2413
2414  ```js
2415  let dirPath = pathDir + "/test";
2416  let isDirectory = fs.statSync(dirPath).isDirectory();
2417  ```
2418
2419### isFIFO
2420
2421isFIFO(): boolean
2422
2423用于判断文件是否是命名管道(有时也称为FIFO)。命名管道通常用于进程间通信。
2424
2425**系统能力**:SystemCapability.FileManagement.File.FileIO
2426
2427**返回值:**
2428
2429  | 类型      | 说明                    |
2430  | ------- | --------------------- |
2431  | boolean | 表示文件是否是&nbsp;FIFO。 |
2432
2433**错误码:**
2434
2435接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2436
2437**示例:**
2438
2439  ```js
2440  let filePath = pathDir + "/test.txt";
2441  let isFIFO = fs.statSync(filePath).isFIFO();
2442  ```
2443
2444### isFile
2445
2446isFile(): boolean
2447
2448用于判断文件是否是普通文件。
2449
2450**系统能力**:SystemCapability.FileManagement.File.FileIO
2451
2452**返回值:**
2453
2454  | 类型      | 说明              |
2455  | ------- | --------------- |
2456  | boolean | 表示文件是否是普通文件。 |
2457
2458**错误码:**
2459
2460接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2461
2462**示例:**
2463
2464  ```js
2465  let filePath = pathDir + "/test.txt";
2466  let isFile = fs.statSync(filePath).isFile();
2467  ```
2468
2469### isSocket
2470
2471isSocket(): boolean
2472
2473用于判断文件是否是套接字。
2474
2475**系统能力**:SystemCapability.FileManagement.File.FileIO
2476
2477**返回值:**
2478
2479  | 类型      | 说明             |
2480  | ------- | -------------- |
2481  | boolean | 表示文件是否是套接字。 |
2482
2483**错误码:**
2484
2485接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2486
2487**示例:**
2488
2489  ```js
2490  let filePath = pathDir + "/test.txt";
2491  let isSocket = fs.statSync(filePath).isSocket();
2492  ```
2493
2494### isSymbolicLink
2495
2496isSymbolicLink(): boolean
2497
2498用于判断文件是否是符号链接。
2499
2500**系统能力**:SystemCapability.FileManagement.File.FileIO
2501
2502**返回值:**
2503
2504  | 类型      | 说明              |
2505  | ------- | --------------- |
2506  | boolean | 表示文件是否是符号链接。 |
2507
2508**错误码:**
2509
2510接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2511
2512**示例:**
2513
2514  ```js
2515  let filePath = pathDir + "/test";
2516  let isSymbolicLink = fs.statSync(filePath).isSymbolicLink();
2517  ```
2518
2519## Stream
2520
2521文件流,在调用Stream的方法前,需要先通过createStream()方法(同步或异步)来构建一个Stream实例。
2522
2523### close
2524
2525close(): Promise&lt;void&gt;
2526
2527关闭文件流,使用Promise异步回调。
2528
2529**系统能力**:SystemCapability.FileManagement.File.FileIO
2530
2531**返回值:**
2532
2533  | 类型                  | 说明            |
2534  | ------------------- | ------------- |
2535  | Promise&lt;void&gt; | Promise对象。返回表示异步关闭文件流的结果。 |
2536
2537**错误码:**
2538
2539接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2540
2541**示例:**
2542
2543  ```js
2544  let filePath = pathDir + "/test.txt";
2545  let ss= fs.createStreamSync(filePath, "r+");
2546  ss.close().then(() => {
2547      console.info("close fileStream succeed");
2548  }).catch((err) => {
2549      console.info("close fileStream  failed with error message: " + err.message + ", error code: " + err.code);
2550  });
2551  ```
2552
2553### close
2554
2555close(callback: AsyncCallback&lt;void&gt;): void
2556
2557异步关闭文件流,使用callback异步回调。
2558
2559**系统能力**:SystemCapability.FileManagement.File.FileIO
2560
2561**参数:**
2562
2563  | 参数名      | 类型                        | 必填   | 说明            |
2564  | -------- | ------------------------- | ---- | ------------- |
2565  | callback | AsyncCallback&lt;void&gt; | 是    | 异步关闭文件流之后的回调。 |
2566
2567**错误码:**
2568
2569接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2570
2571**示例:**
2572
2573  ```js
2574  let filePath = pathDir + "/test.txt";
2575  let ss= fs.createStreamSync(filePath, "r+");
2576  ss.close((err) => {
2577    if (err) {
2578      console.info("close stream failed with error message: " + err.message + ", error code: " + err.code);
2579    } else {
2580      console.info("close stream success");
2581    }
2582  });
2583  ```
2584
2585### closeSync
2586
2587closeSync(): void
2588
2589同步关闭文件流。
2590
2591**系统能力**:SystemCapability.FileManagement.File.FileIO
2592
2593**错误码:**
2594
2595接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2596
2597**示例:**
2598
2599  ```js
2600  let filePath = pathDir + "/test.txt";
2601  let ss= fs.createStreamSync(filePath, "r+");
2602  ss.closeSync();
2603  ```
2604
2605### flush
2606
2607flush(): Promise&lt;void&gt;
2608
2609刷新文件流,使用Promise异步回调。
2610
2611**系统能力**:SystemCapability.FileManagement.File.FileIO
2612
2613**返回值:**
2614
2615  | 类型                  | 说明            |
2616  | ------------------- | ------------- |
2617  | Promise&lt;void&gt; | Promise对象。返回表示异步刷新文件流的结果。 |
2618
2619**错误码:**
2620
2621接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2622
2623**示例:**
2624
2625  ```js
2626  let filePath = pathDir + "/test.txt";
2627  let ss= fs.createStreamSync(filePath, "r+");
2628  ss.flush().then(() => {
2629      console.info("flush succeed");
2630  }).catch((err) => {
2631      console.info("flush failed with error message: " + err.message + ", error code: " + err.code);
2632  });
2633  ```
2634
2635### flush
2636
2637flush(callback: AsyncCallback&lt;void&gt;): void
2638
2639异步刷新文件流,使用callback异步回调。
2640
2641**系统能力**:SystemCapability.FileManagement.File.FileIO
2642
2643**参数:**
2644
2645  | 参数名      | 类型                        | 必填   | 说明             |
2646  | -------- | ------------------------- | ---- | -------------- |
2647  | callback | AsyncCallback&lt;void&gt; | 是    | 异步刷新文件流后的回调函数。 |
2648
2649**错误码:**
2650
2651接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2652
2653**示例:**
2654
2655  ```js
2656  let filePath = pathDir + "/test.txt";
2657  let ss= fs.createStreamSync(filePath, "r+");
2658  ss.flush((err) => {
2659    if (err) {
2660      console.info("flush stream failed with error message: " + err.message + ", error code: " + err.code);
2661    } else {
2662      console.info("flush success");
2663    }
2664  });
2665  ```
2666
2667### flushSync
2668
2669flushSync(): void
2670
2671同步刷新文件流。
2672
2673**系统能力**:SystemCapability.FileManagement.File.FileIO
2674
2675**错误码:**
2676
2677接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2678
2679**示例:**
2680
2681  ```js
2682  let filePath = pathDir + "/test.txt";
2683  let ss= fs.createStreamSync(filePath, "r+");
2684  ss.flushSync();
2685  ```
2686
2687### write
2688
2689write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }): Promise&lt;number&gt;
2690
2691将数据写入流文件,使用Promise异步回调。
2692
2693**系统能力**:SystemCapability.FileManagement.File.FileIO
2694
2695**参数:**
2696
2697  | 参数名     | 类型                              | 必填   | 说明                                       |
2698  | ------- | ------------------------------- | ---- | ---------------------------------------- |
2699  | buffer  | ArrayBuffer\|string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
2700  | options | Object                          | 否    | 支持如下选项:<br/>-&nbsp;length,number类型,表示期望写入数据的长度。默认缓冲区长度。<br/>-&nbsp;offset,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。仅支持&nbsp;'utf-8'。|
2701
2702**返回值:**
2703
2704  | 类型                    | 说明       |
2705  | --------------------- | -------- |
2706  | Promise&lt;number&gt; | Promise对象。返回实际写入的长度。 |
2707
2708**错误码:**
2709
2710接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2711
2712**示例:**
2713
2714  ```js
2715  let filePath = pathDir + "/test.txt";
2716  let ss= fs.createStreamSync(filePath, "r+");
2717  ss.write("hello, world",{ offset: 5, length: 5, encoding: 'utf-8' }).then((number) => {
2718      console.info("write succeed and size is:" + number);
2719  }).catch((err) => {
2720      console.info("write failed with error message: " + err.message + ", error code: " + err.code);
2721  });
2722  ```
2723
2724### write
2725
2726write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;number&gt;): void
2727
2728将数据写入流文件,使用callback异步回调。
2729
2730**系统能力**:SystemCapability.FileManagement.File.FileIO
2731
2732**参数:**
2733
2734  | 参数名   | 类型                            | 必填 | 说明                                                         |
2735  | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
2736  | buffer   | ArrayBuffer\|string | 是   | 待写入文件的数据,可来自缓冲区或字符串。                     |
2737  | options  | Object                          | 否   | 支持如下选项:<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度。<br/>-&nbsp;offset,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。仅支持&nbsp;'utf-8'。|
2738  | callback | AsyncCallback&lt;number&gt;     | 是   | 异步写入完成后执行的回调函数。                               |
2739
2740**错误码:**
2741
2742接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2743
2744**示例:**
2745
2746  ```js
2747  let filePath = pathDir + "/test.txt";
2748  let ss= fs.createStreamSync(filePath, "r+");
2749  ss.write("hello, world", { offset: 5, length: 5, encoding :'utf-8'}, (err, bytesWritten) => {
2750    if (err) {
2751      console.info("write stream failed with error message: " + err.message + ", error code: " + err.code);
2752    } else {
2753      if (bytesWritten) {
2754        console.info("write succeed and size is:" + bytesWritten);
2755      }
2756    }
2757  });
2758  ```
2759
2760### writeSync
2761
2762writeSync(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }): number
2763
2764以同步方法将数据写入流文件。
2765
2766**系统能力**:SystemCapability.FileManagement.File.FileIO
2767
2768**参数:**
2769
2770  | 参数名     | 类型                              | 必填   | 说明                                       |
2771  | ------- | ------------------------------- | ---- | ---------------------------------------- |
2772  | buffer  | ArrayBuffer\|string | 是    | 待写入文件的数据,可来自缓冲区或字符串。                     |
2773  | options | Object                          | 否    | 支持如下选项:<br/>-&nbsp;length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度。<br/>-&nbsp;offset,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。<br/>-&nbsp;encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认&nbsp;'utf-8'。仅支持&nbsp;'utf-8'。|
2774
2775**返回值:**
2776
2777  | 类型     | 说明       |
2778  | ------ | -------- |
2779  | number | 实际写入的长度。 |
2780
2781**错误码:**
2782
2783接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2784
2785**示例:**
2786
2787  ```js
2788  let filePath = pathDir + "/test.txt";
2789  let ss= fs.createStreamSync(filePath,"r+");
2790  let num = ss.writeSync("hello, world", {offset: 5, length: 5, encoding :'utf-8'});
2791  ```
2792
2793### read
2794
2795read(buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): Promise&lt;number&gt;
2796
2797从流文件读取数据,使用Promise异步回调。
2798
2799**系统能力**:SystemCapability.FileManagement.File.FileIO
2800
2801**参数:**
2802
2803  | 参数名     | 类型          | 必填   | 说明                                       |
2804  | ------- | ----------- | ---- | ---------------------------------------- |
2805  | buffer  | ArrayBuffer | 是    | 用于读取文件的缓冲区。                              |
2806  | options | Object      | 否    | 支持如下选项:<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度。<br/>-&nbsp;offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。 |
2807
2808**返回值:**
2809
2810  | 类型                                 | 说明     |
2811  | ---------------------------------- | ------ |
2812  | Promise&lt;number&gt; | Promise对象。返回读取的结果。 |
2813
2814**错误码:**
2815
2816接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2817
2818**示例:**
2819
2820  ```js
2821  let filePath = pathDir + "/test.txt";
2822  let ss = fs.createStreamSync(filePath, "r+");
2823  let buf = new ArrayBuffer(4096);
2824  ss.read(buf, {offset: 5, length: 5}).then((readLen) => {
2825    console.info("read data succeed");
2826    console.log(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
2827  }).catch((err) => {
2828      console.info("read data failed with error message: " + err.message + ", error code: " + err.code);
2829  });
2830  ```
2831
2832### read
2833
2834read(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length?: number; }, callback: AsyncCallback&lt;number&gt;): void
2835
2836从流文件读取数据,使用callback异步回调。
2837
2838**系统能力**:SystemCapability.FileManagement.File.FileIO
2839
2840**参数:**
2841
2842  | 参数名      | 类型                                       | 必填   | 说明                                       |
2843  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2844  | buffer   | ArrayBuffer                              | 是    | 用于读取文件的缓冲区。                              |
2845  | options  | Object                                   | 否    | 支持如下选项:<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度。<br/>-&nbsp;offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读. |
2846  | callback | AsyncCallback&lt;number&gt; | 是    | 异步从流文件读取数据之后的回调。                         |
2847
2848**错误码:**
2849
2850接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2851
2852**示例:**
2853
2854  ```js
2855  let filePath = pathDir + "/test.txt";
2856  let ss = fs.createStreamSync(filePath, "r+");
2857  let buf = new ArrayBuffer(4096)
2858  ss.read(buf, {offset: 5, length: 5}, (err, readLen) => {
2859    if (err) {
2860      console.info("read stream failed with error message: " + err.message + ", error code: " + err.code);
2861    } else {
2862      console.info("read data succeed");
2863      console.log(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
2864    }
2865  });
2866  ```
2867
2868### readSync
2869
2870readSync(buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): number
2871
2872以同步方法从流文件读取数据。
2873
2874**系统能力**:SystemCapability.FileManagement.File.FileIO
2875
2876**参数:**
2877
2878  | 参数名     | 类型          | 必填   | 说明                                       |
2879  | ------- | ----------- | ---- | ---------------------------------------- |
2880  | buffer  | ArrayBuffer | 是    | 用于读取文件的缓冲区。                              |
2881  | options | Object      | 否    | 支持如下选项:<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度。<br/>-&nbsp;offset,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。<br/>  |
2882
2883**返回值:**
2884
2885  | 类型     | 说明       |
2886  | ------ | -------- |
2887  | number | 实际读取的长度。 |
2888
2889**错误码:**
2890
2891接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2892
2893**示例:**
2894
2895  ```js
2896  let filePath = pathDir + "/test.txt";
2897  let ss = fs.createStreamSync(filePath, "r+");
2898  let num = ss.readSync(new ArrayBuffer(4096), {offset: 5, length: 5});
2899  ```
2900
2901## File
2902
2903由open接口打开的File对象。
2904
2905**系统能力**:SystemCapability.FileManagement.File.FileIO
2906
2907### 属性
2908
2909| 名称   | 类型   | 可读   | 可写   | 说明      |
2910| ---- | ------ | ---- | ---- | ------- |
2911| fd | number | 是    | 否    | 打开的文件描述符。 |
2912
2913### lock
2914
2915lock(exclusive?: boolean): Promise\<void>
2916
2917文件阻塞式施加共享锁或独占锁,使用Promise异步回调。
2918
2919**系统能力**:SystemCapability.FileManagement.File.FileIO
2920
2921**参数:**
2922
2923  | 参数名     | 类型          | 必填   | 说明                                       |
2924  | ------- | ----------- | ---- | ---------------------------------------- |
2925  | exclusive  | boolean | 否   | 是否施加独占锁,默认false。       |
2926
2927**返回值:**
2928
2929  | 类型                                 | 说明     |
2930  | ---------------------------------- | ------ |
2931  | Promise&lt;void&gt; | Promise对象。无返回值。 |
2932
2933**错误码:**
2934
2935接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2936
2937**示例:**
2938
2939  ```js
2940  let file = fs.openSync(pathDir + "/test.txt", fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
2941  file.lock(true).then(() => {
2942    console.log("lock file successful");
2943  }).catch((err) => {
2944      console.info("lock file failed with error message: " + err.message + ", error code: " + err.code);
2945  });
2946  ```
2947
2948### lock
2949
2950lock(exclusive?: boolean, callback: AsyncCallback\<void>): void
2951
2952文件阻塞式施加共享锁或独占锁,使Callback异步回调。
2953
2954**系统能力**:SystemCapability.FileManagement.File.FileIO
2955
2956**参数:**
2957
2958  | 参数名     | 类型          | 必填   | 说明                                       |
2959  | ------- | ----------- | ---- | ---------------------------------------- |
2960  | exclusive  | boolean | 否   | 是否施加独占锁,默认false。       |
2961  | callback | AsyncCallback&lt;void&gt; | 是    | 异步文件上锁之后的回调。   |
2962
2963**错误码:**
2964
2965接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2966
2967**示例:**
2968
2969  ```js
2970  let file = fs.openSync(pathDir + "/test.txt", fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
2971  file.lock(true, (err) => {
2972    if (err) {
2973      console.info("lock file failed with error message: " + err.message + ", error code: " + err.code);
2974    } else {
2975      console.log("lock file successful");
2976    }
2977  });
2978  ```
2979
2980### tryLock
2981
2982tryLock(exclusive?: boolean): void
2983
2984文件非阻塞式施加共享锁或独占锁。
2985
2986**系统能力**:SystemCapability.FileManagement.File.FileIO
2987
2988**参数:**
2989
2990  | 参数名     | 类型          | 必填   | 说明                                       |
2991  | ------- | ----------- | ---- | ---------------------------------------- |
2992  | exclusive  | boolean | 否   | 是否施加独占锁,默认false。       |
2993
2994**错误码:**
2995
2996接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
2997
2998**示例:**
2999
3000  ```js
3001  let file = fs.openSync(pathDir + "/test.txt", fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
3002  file.tryLock(true);
3003  console.log("lock file successful");
3004  ```
3005
3006### unlock
3007
3008unlock(): void
3009
3010以同步方式给文件解锁。
3011
3012**系统能力**:SystemCapability.FileManagement.File.FileIO
3013
3014**错误码:**
3015
3016接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。
3017
3018**示例:**
3019
3020  ```js
3021  let file = fs.openSync(pathDir + "/test.txt", fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
3022  file.tryLock(true);
3023  file.unlock();
3024  console.log("unlock file successful");
3025  ```
3026
3027## OpenMode
3028
3029open接口flags参数常量。文件打开标签。
3030
3031**系统能力**:SystemCapability.FileManagement.File.FileIO
3032
3033| 名称   | 类型   | 值  | 说明      |
3034| ---- | ------ |---- | ------- |
3035| READ_ONLY | number |  0o0   | 只读打开。 |
3036| WRITE_ONLY | number | 0o1    | 只写打开。 |
3037| READ_WRITE | number | 0o2    | 读写打开。 |
3038| CREATE | number | 0o100    | 若文件不存在,则创建文件。 |
3039| TRUNC | number | 0o1000    | 如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。 |
3040| APPEND | number | 0o2000   | 以追加方式打开,后续写将追加到文件末尾。 |
3041| NONBLOCK | number | 0o4000    | 如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续 IO 进行非阻塞操作。 |
3042| DIR | number | 0o200000    | 如果path不指向目录,则出错。 |
3043| NOFOLLOW | number | 0o400000    | 如果path指向符号链接,则出错。 |
3044| SYNC | number | 0o4010000    | 以同步IO的方式打开文件。 |
3045
3046## Filter
3047
3048**系统能力**:SystemCapability.FileManagement.File.FileIO
3049
3050文件过滤配置项类型,支持listFile接口使用。
3051
3052| 名称        | 类型       | 说明                |
3053| ----------- | --------------- | ------------------ |
3054| suffix | Array&lt;string&gt;     | 文件后缀名完全匹配,各个关键词OR关系。           |
3055| displayName    | Array&lt;string&gt;     | 文件名模糊匹配,各个关键词OR关系。 |
3056| mimeType    | Array&lt;string&gt; | mime类型完全匹配,各个关键词OR关系。       |
3057| fileSizeOver    | number | 文件大小匹配,大于等于指定大小的文件。       |
3058| lastModifiedAfter    | number | 文件最近修改时间匹配,在指定时间点及之后的文件。       |
3059| excludeMedia    | boolean | 是否排除Media中已有的文件。       |
3060