• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.fileio (File Management)
2
3The **fileio** module provides APIs for file storage and management, including basic file management, directory management, file information statistics, and stream read and write.
4
5> **NOTE**
6> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
7> - The APIs provided by this module are deprecated since API version 9. You are advised to use [@ohos.file.fs](js-apis-file-fs.md).
8
9## Modules to Import
10
11```ts
12import fileio from '@ohos.fileio';
13```
14
15
16## Guidelines
17
18Before using the APIs provided by this module to perform operations on a file or directory, obtain the application sandbox path of the file or directory as follows:
19
20**Stage Model**
21
22 ```ts
23  import UIAbility from '@ohos.app.ability.UIAbility';
24  import window from '@ohos.window';
25
26  export default class EntryAbility extends UIAbility {
27    onWindowStageCreate(windowStage: window.WindowStage) {
28      let context = this.context;
29      let pathDir = context.filesDir;
30    }
31  }
32  ```
33
34 For details about how to obtain the stage model context, see [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md).
35
36**FA Model**
37
38  ```js
39  import featureAbility from '@ohos.ability.featureAbility';
40
41  let context = featureAbility.getContext();
42  context.getFilesDir().then((data) => {
43    let pathDir = data;
44  })
45  ```
46
47 For details about how to obtain the FA model context, see [Context](js-apis-inner-app-context.md#context).
48
49## fileio.stat
50
51stat(path: string): Promise<Stat>
52
53Obtains file information. This API uses a promise to return the result.
54
55> **NOTE**
56>
57> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#stat) instead.
58
59**System capability**: SystemCapability.FileManagement.File.FileIO
60
61**Parameters**
62
63| Name| Type  | Mandatory| Description                      |
64| ------ | ------ | ---- | -------------------------- |
65| path   | string | Yes  | Application sandbox path of the file.|
66
67**Return value**
68
69  | Type                          | Description        |
70  | ---------------------------- | ---------- |
71| Promise<[Stat](#stat)> | Promise used to return the file information obtained.|
72
73**Example**
74
75  ```ts
76  import { BusinessError } from '@ohos.base';
77  let filePath = pathDir + "test.txt";
78  fileio.stat(filePath).then((stat: fileio.Stat) => {
79    console.info("getFileInfo succeed, the size of file is " + stat.size);
80  }).catch((err: BusinessError) => {
81    console.info("getFileInfo failed with error:" + err);
82  });
83  ```
84
85
86## fileio.stat
87
88stat(path: string, callback: AsyncCallback<Stat>): void
89
90Obtains file information. This API uses an asynchronous callback to return the result.
91
92> **NOTE**
93>
94> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#fsstat-1) instead.
95
96**System capability**: SystemCapability.FileManagement.File.FileIO
97
98**Parameters**
99
100| Name  | Type                              | Mandatory| Description                          |
101| -------- | ---------------------------------- | ---- | ------------------------------ |
102| path     | string                             | Yes  | Application sandbox path of the file.    |
103| callback | AsyncCallback<[Stat](#stat)> | Yes  | Callback invoked to return the file information obtained.|
104
105**Example**
106
107  ```ts
108  import { BusinessError } from '@ohos.base';
109  fileio.stat(pathDir, (err: BusinessError, stat: fileio.Stat) => {
110    // Example code in Stat
111  });
112  ```
113
114
115## fileio.statSync
116
117statSync(path: string): Stat
118
119Obtains file information. This API returns the result synchronously.
120
121> **NOTE**
122>
123> This API is deprecated since API version 9. Use [fs.statSync](js-apis-file-fs.md#fsstatsync) instead.
124
125**System capability**: SystemCapability.FileManagement.File.FileIO
126
127**Parameters**
128
129| Name| Type  | Mandatory| Description                      |
130| ------ | ------ | ---- | -------------------------- |
131| path   | string | Yes  | Application sandbox path of the file.|
132
133
134**Return value**
135
136  | Type           | Description        |
137  | ------------- | ---------- |
138  | [Stat](#stat) | File information obtained.|
139
140**Example**
141
142  ```ts
143  let stat = fileio.statSync(pathDir);
144  // Example code in Stat
145  ```
146
147
148## fileio.opendir
149
150opendir(path: string): Promise<Dir>
151
152Opens a directory. This API uses a promise to return the result.
153
154> **NOTE**
155>
156> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead.
157
158**System capability**: SystemCapability.FileManagement.File.FileIO
159
160**Parameters**
161
162| Name| Type  | Mandatory| Description                          |
163| ------ | ------ | ---- | ------------------------------ |
164| path   | string | Yes  | Application sandbox path of the directory to open.|
165
166**Return value**
167
168  | Type                        | Description      |
169  | -------------------------- | -------- |
170| Promise<[Dir](#dir)> | Promise used to return the **Dir** object opened.|
171
172**Example**
173
174  ```ts
175  import { BusinessError } from '@ohos.base';
176  let dirPath = pathDir + "/testDir";
177  fileio.opendir(dirPath).then((dir: fileio.Dir) => {
178    console.info("opendir succeed");
179  }).catch((err: BusinessError) => {
180    console.info("opendir failed with error:" + err);
181  });
182  ```
183
184
185## fileio.opendir
186
187opendir(path: string, callback: AsyncCallback<Dir>): void
188
189Opens a file directory. This API uses an asynchronous callback to return the result.
190
191> **NOTE**
192>
193> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile-1) instead.
194
195**System capability**: SystemCapability.FileManagement.File.FileIO
196
197**Parameters**
198
199| Name  | Type                            | Mandatory| Description                          |
200| -------- | -------------------------------- | ---- | ------------------------------ |
201| path     | string                           | Yes  | Application sandbox path of the directory to open.|
202| callback | AsyncCallback<[Dir](#dir)> | Yes  | Callback invoked when the directory is open asynchronously.  |
203
204**Example**
205
206  ```ts
207  import { BusinessError } from '@ohos.base';
208  fileio.opendir(pathDir, (err: BusinessError, dir: fileio.Dir) => {
209    // Example code in Dir struct
210    // Use read/readSync/close.
211  });
212  ```
213
214
215## fileio.opendirSync
216
217opendirSync(path: string): Dir
218
219Opens a directory. This API returns the result synchronously.
220
221> **NOTE**
222>
223> This API is deprecated since API version 9. Use [fs.listFileSync](js-apis-file-fs.md#fslistfilesync) instead.
224
225**System capability**: SystemCapability.FileManagement.File.FileIO
226
227**Parameters**
228
229| Name| Type  | Mandatory| Description                          |
230| ------ | ------ | ---- | ------------------------------ |
231| path   | string | Yes  | Application sandbox path of the directory to open.|
232
233**Return value**
234
235  | Type         | Description      |
236  | ----------- | -------- |
237  | [Dir](#dir) | A **Dir** instance corresponding to the directory.|
238
239**Example**
240
241  ```ts
242  let dir = fileio.opendirSync(pathDir);
243  // Example code in Dir struct
244  // Use read/readSync/close.
245  ```
246
247
248## fileio.access
249
250access(path: string, mode?: number): Promise<void>
251
252Checks whether the current process can access a file. This API uses a promise to return the result.
253
254> **NOTE**
255>
256> This API is deprecated since API version 9. Use [fs.access](js-apis-file-fs.md#fsaccess) instead.
257
258**System capability**: SystemCapability.FileManagement.File.FileIO
259
260**Parameters**
261
262| Name| Type  | Mandatory| Description                                                        |
263| ------ | ------ | ---- | ------------------------------------------------------------ |
264| path   | string | Yes  | Application sandbox path of the file.                                  |
265| mode   | number | No  | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>- **0**: Check whether the file exists.<br>- **1**: Check whether the process has the execute permission on the file.<br>- **2**: Check whether the process has the write permission on the file.<br>- **4**: Check whether the process has the read permission on the file.|
266
267**Return value**
268
269  | Type                 | Description                          |
270  | ------------------- | ---------------------------- |
271  | Promise&lt;void&gt; | Promise that returns no value.|
272
273**Example**
274
275  ```ts
276  import { BusinessError } from '@ohos.base';
277  let filePath = pathDir + "/test.txt";
278  fileio.access(filePath).then(() => {
279    console.info("Access successful");
280  }).catch((err: BusinessError) => {
281    console.info("access failed with error:" + err);
282  });
283  ```
284
285
286## fileio.access
287
288access(path: string, mode?: number, callback: AsyncCallback&lt;void&gt;): void
289
290Checks whether the current process can access a file. This API uses an asynchronous callback to return the result.
291
292> **NOTE**
293>
294> This API is deprecated since API version 9. Use [fs.access](js-apis-file-fs.md#fsaccess-1) instead.
295
296**System capability**: SystemCapability.FileManagement.File.FileIO
297
298**Parameters**
299
300| Name  | Type                     | Mandatory| Description                                                        |
301| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
302| path     | string                    | Yes  | Application sandbox path of the file.                                  |
303| mode     | number                    | No  | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>- **0**: Check whether the file exists.<br>- **1**: Check whether the process has the execute permission on the file.<br>- **2**: Check whether the process has the write permission on the file.<br>- **4**: Check whether the process has the read permission on the file.|
304| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked when the file is asynchronously checked.                |
305
306**Example**
307
308  ```ts
309  import { BusinessError } from '@ohos.base';
310  let filePath = pathDir + "/test.txt";
311  fileio.access(filePath, (err: BusinessError) => {
312    // Do something.
313  });
314  ```
315
316
317## fileio.accessSync
318
319accessSync(path: string, mode?: number): void
320
321Checks whether the current process can access the specified file. This API returns the result synchronously.
322
323> **NOTE**
324>
325> This API is deprecated since API version 9. Use [fs.accessSync](js-apis-file-fs.md#fsaccesssync) instead.
326
327**System capability**: SystemCapability.FileManagement.File.FileIO
328
329**Parameters**
330
331| Name| Type  | Mandatory| Description                                                        |
332| ------ | ------ | ---- | ------------------------------------------------------------ |
333| path   | string | Yes  | Application sandbox path of the file.                                  |
334| mode   | number | No  | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>- **0**: Check whether the file exists.<br>- **1**: Check whether the process has the execute permission on the file.<br>- **2**: Check whether the process has the write permission on the file.<br>- **4**: Check whether the process has the read permission on the file.|
335
336**Example**
337
338  ```ts
339  import { BusinessError } from '@ohos.base';
340  let filePath = pathDir + "/test.txt";
341  try {
342    fileio.accessSync(filePath);
343  } catch(err: BusinessError) {
344    console.info("accessSync failed with error:" + err);
345  }
346  ```
347
348
349## fileio.close<sup>7+</sup>
350
351close(fd: number): Promise&lt;void&gt;
352
353Closes a file. This API uses a promise to return the result.
354
355> **NOTE**
356>
357> This API is deprecated since API version 9. Use [fs.close](js-apis-file-fs.md#fsclose) instead.
358
359**System capability**: SystemCapability.FileManagement.File.FileIO
360
361**Parameters**
362
363  | Name | Type    | Mandatory  | Description          |
364  | ---- | ------ | ---- | ------------ |
365  | fd   | number | Yes   | File descriptor of the file to close.|
366
367**Return value**
368
369  | Type                 | Description                          |
370  | ------------------- | ---------------------------- |
371  | Promise&lt;void&gt; | Promise that returns no value.|
372
373**Example**
374
375  ```ts
376  import { BusinessError } from '@ohos.base';
377  let filePath = pathDir + "/test.txt";
378  let fd = fileio.openSync(filePath);
379  fileio.close(fd).then(() => {
380    console.info("File closed");
381  }).catch((err: BusinessError) => {
382    console.info("close file failed with error:" + err);
383  });
384  ```
385
386
387## fileio.close<sup>7+</sup>
388
389close(fd: number, callback: AsyncCallback&lt;void&gt;): void
390
391Closes a file. This API uses an asynchronous callback to return the result.
392
393> **NOTE**
394>
395> This API is deprecated since API version 9. Use [fs.close](js-apis-file-fs.md#fsclose-1) instead.
396
397**System capability**: SystemCapability.FileManagement.File.FileIO
398
399**Parameters**
400
401  | Name     | Type                       | Mandatory  | Description          |
402  | -------- | ------------------------- | ---- | ------------ |
403  | fd       | number                    | Yes   | File descriptor of the file to close.|
404  | callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked immediately after the file is closed.|
405
406**Example**
407
408  ```ts
409  import { BusinessError } from '@ohos.base';
410  let filePath = pathDir + "/test.txt";
411  let fd = fileio.openSync(filePath);
412  fileio.close(fd, (err: BusinessError) => {
413    // Do something.
414  });
415  ```
416
417
418## fileio.closeSync
419
420closeSync(fd: number): void
421
422Closes a file. This API returns the result synchronously.
423
424> **NOTE**
425>
426> This API is deprecated since API version 9. Use [fs.closeSync](js-apis-file-fs.md#fsclosesync) instead.
427
428**System capability**: SystemCapability.FileManagement.File.FileIO
429
430**Parameters**
431
432  | Name | Type    | Mandatory  | Description          |
433  | ---- | ------ | ---- | ------------ |
434  | fd   | number | Yes   | File descriptor of the file to close.|
435
436**Example**
437
438  ```ts
439  let filePath = pathDir + "/test.txt";
440  let fd = fileio.openSync(filePath);
441  fileio.closeSync(fd);
442  ```
443
444
445## fileio.copyFile
446
447copyFile(src: string|number, dest: string|number, mode?: number): Promise&lt;void&gt;
448
449Copies a file. This API uses a promise to return the result.
450
451> **NOTE**
452>
453> This API is deprecated since API version 9. Use [fs.copyFile](js-apis-file-fs.md#fscopyfile) instead.
454
455**System capability**: SystemCapability.FileManagement.File.FileIO
456
457**Parameters**
458
459  | Name | Type                        | Mandatory  | Description                                      |
460  | ---- | -------------------------- | ---- | ---------------------------------------- |
461  | src  | string\|number | Yes   | Path or file descriptor of the file to copy.                     |
462  | dest | string\|number | Yes   | Path or file descriptor of the new file.                         |
463  | mode | number                     | No   | Whether to overwrite the file with the same name in the destination directory. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
464
465**Return value**
466
467  | Type                 | Description                          |
468  | ------------------- | ---------------------------- |
469  | Promise&lt;void&gt; | Promise that returns no value.|
470
471**Example**
472
473  ```ts
474  import { BusinessError } from '@ohos.base';
475  let srcPath = pathDir + "srcDir/test.txt";
476  let dstPath = pathDir + "dstDir/test.txt";
477  fileio.copyFile(srcPath, dstPath).then(() => {
478    console.info("File copied");
479  }).catch((err: BusinessError) => {
480    console.info("copyFile failed with error:" + err);
481  });
482  ```
483
484
485## fileio.copyFile
486
487copyFile(src: string|number, dest: string|number, mode: number, callback: AsyncCallback&lt;void&gt;): void
488
489Copies a file. This API uses an asynchronous callback to return the result.
490
491> **NOTE**
492>
493> This API is deprecated since API version 9. Use [fs.copyFile](js-apis-file-fs.md#fscopyfile-1) instead.
494
495**System capability**: SystemCapability.FileManagement.File.FileIO
496
497**Parameters**
498
499  | Name     | Type                        | Mandatory  | Description                                      |
500  | -------- | -------------------------- | ---- | ---------------------------------------- |
501  | src      | string\|number | Yes   | Path or file descriptor of the file to copy.                     |
502  | dest     | string\|number | Yes   | Path or file descriptor of the new file.                         |
503  | mode     | number                     | No   | Whether to overwrite the file with the same name in the destination directory. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
504  | callback | AsyncCallback&lt;void&gt;  | Yes   | Callback invoked immediately after the file is copied.                            |
505
506**Example**
507
508  ```ts
509  import { BusinessError } from '@ohos.base';
510  let srcPath = pathDir + "srcDir/test.txt";
511  let dstPath = pathDir + "dstDir/test.txt";
512  fileio.copyFile(srcPath, dstPath, (err: BusinessError) => {
513    // Do something.
514  });
515  ```
516
517
518## fileio.copyFileSync
519
520copyFileSync(src: string|number, dest: string|number, mode?: number): void
521
522Copies a file. This API returns the result synchronously.
523
524> **NOTE**
525>
526> This API is deprecated since API version 9. Use [fs.copyFileSync](js-apis-file-fs.md#fscopyfilesync) instead.
527
528**System capability**: SystemCapability.FileManagement.File.FileIO
529
530**Parameters**
531
532  | Name | Type                        | Mandatory  | Description                                      |
533  | ---- | -------------------------- | ---- | ---------------------------------------- |
534  | src  | string\|number | Yes   | Path or file descriptor of the file to copy.                     |
535  | dest | string\|number | Yes   | Path or file descriptor of the new file.                         |
536  | mode | number                     | No   | Whether to overwrite the file with the same name in the destination directory. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
537
538**Example**
539
540  ```ts
541  let srcPath = pathDir + "srcDir/test.txt";
542  let dstPath = pathDir + "dstDir/test.txt";
543  fileio.copyFileSync(srcPath, dstPath);
544  ```
545
546
547## fileio.mkdir
548
549mkdir(path: string, mode?: number): Promise&lt;void&gt;
550
551Creates a directory. This API uses a promise to return the result.
552
553> **NOTE**
554>
555> This API is deprecated since API version 9. Use [fs.mkdir](js-apis-file-fs.md#fsmkdir) instead.
556
557**System capability**: SystemCapability.FileManagement.File.FileIO
558
559**Parameters**
560
561| Name| Type  | Mandatory| Description                                                        |
562| ------ | ------ | ---- | ------------------------------------------------------------ |
563| path   | string | Yes  | Application sandbox path of the directory.                                  |
564| mode   | number | No  | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
565
566**Return value**
567
568  | Type                 | Description                          |
569  | ------------------- | ---------------------------- |
570  | Promise&lt;void&gt; | Promise that returns no value.|
571
572**Example**
573
574  ```ts
575  import { BusinessError } from '@ohos.base';
576  let dirPath = pathDir + '/testDir';
577  fileio.mkdir(dirPath).then(() => {
578    console.info("Directory created");
579  }).catch((error: BusinessError) => {
580    console.info("mkdir failed with error:" + error);
581  });
582  ```
583
584
585## fileio.mkdir
586
587mkdir(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
588
589Creates a directory. This API uses an asynchronous callback to return the result.
590
591> **NOTE**
592>
593> This API is deprecated since API version 9. Use [fs.mkdir](js-apis-file-fs.md#fsmkdir-1) instead.
594
595**System capability**: SystemCapability.FileManagement.File.FileIO
596
597**Parameters**
598
599| Name  | Type                     | Mandatory| Description                                                        |
600| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
601| path     | string                    | Yes  | Application sandbox path of the directory.                                  |
602| mode     | number                    | No  | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
603| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked when the directory is created asynchronously.                            |
604
605**Example**
606
607  ```ts
608  import { BusinessError } from '@ohos.base';
609  let dirPath = pathDir + '/testDir';
610  fileio.mkdir(dirPath, (err: BusinessError) => {
611    console.info("Directory created");
612  });
613  ```
614
615
616## fileio.mkdirSync
617
618mkdirSync(path: string, mode?: number): void
619
620Creates a directory. This API returns the result synchronously.
621
622> **NOTE**
623>
624> This API is deprecated since API version 9. Use [fs.mkdirSync](js-apis-file-fs.md#fsmkdirsync) instead.
625
626**System capability**: SystemCapability.FileManagement.File.FileIO
627
628**Parameters**
629
630| Name| Type  | Mandatory| Description                                                        |
631| ------ | ------ | ---- | ------------------------------------------------------------ |
632| path   | string | Yes  | Application sandbox path of the directory.                                  |
633| mode   | number | No  | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
634
635**Example**
636
637  ```ts
638  let dirPath = path + '/testDir';
639  fileio.mkdirSync(dirPath);
640  ```
641
642
643## fileio.open<sup>7+</sup>
644
645open(path: string, flags?: number, mode?: number): Promise&lt;number&gt;
646
647Opens a file. This API uses a promise to return the result.
648
649> **NOTE**
650>
651> This API is deprecated since API version 9. Use [fs.open](js-apis-file-fs.md#fsopen) instead.
652
653**System capability**: SystemCapability.FileManagement.File.FileIO
654
655**Parameters**
656
657| Name| Type  | Mandatory| Description                                                        |
658| ------ | ------ | ---- | ------------------------------------------------------------ |
659| path   | string | Yes  | Application sandbox path of the file.                                  |
660| flags  | number | No  | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **0o200000**: If **path** does not point to a directory, throw an exception.<br><br/>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.|
661| mode   | number | No  | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o660**.<br>- **0o660**: The owner and user group have the read and write permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
662
663**Return value**
664
665  | Type                   | Description         |
666  | --------------------- | ----------- |
667| Promise&lt;number&gt; | Promise used to return the file descriptor of the file opened.|
668
669**Example**
670
671  ```ts
672  import { BusinessError } from '@ohos.base';
673  let filePath = pathDir + "/test.txt";
674  fileio.open(filePath, 0o1, 0o0200).then((number: number) => {
675    console.info("File opened");
676  }).catch((err: BusinessError) => {
677    console.info("open file failed with error:" + err);
678  });
679  ```
680
681
682## fileio.open<sup>7+</sup>
683
684open(path: string, flags: number, mode: number, callback: AsyncCallback&lt;number&gt;): void
685
686Opens a file. This API uses an asynchronous callback to return the result.
687
688> **NOTE**
689>
690> This API is deprecated since API version 9. Use [fs.open](js-apis-file-fs.md#fsopen-1) instead.
691
692**System capability**: SystemCapability.FileManagement.File.FileIO
693
694**Parameters**
695
696| Name  | Type                           | Mandatory| Description                                                        |
697| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
698| path     | string                          | Yes  | Application sandbox path of the file.                                  |
699| flags    | number                          | No  | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **0o200000**: If **path** does not point to a directory, throw an exception.<br><br/>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.|
700| mode     | number                          | No  | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o660**.<br>- **0o660**: The owner and user group have the read and write permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
701| callback | AsyncCallback&lt;number&gt; | Yes  | Callback invoked when the file is open asynchronously.                                    |
702
703**Example**
704
705  ```ts
706  import { BusinessError } from '@ohos.base';
707  let filePath = pathDir + "/test.txt";
708  fileio.open(filePath, 0, (err: BusinessError, fd: number) => {
709    // Do something.
710  });
711  ```
712
713
714## fileio.openSync
715
716openSync(path: string, flags?: number, mode?: number): number
717
718Opens a file. This API returns the result synchronously.
719
720> **NOTE**
721>
722> This API is deprecated since API version 9. Use [fs.openSync](js-apis-file-fs.md#fsopensync) instead.
723
724**System capability**: SystemCapability.FileManagement.File.FileIO
725
726**Parameters**
727
728| Name| Type  | Mandatory| Description                                                        |
729| ------ | ------ | ---- | ------------------------------------------------------------ |
730| path   | string | Yes  | Application sandbox path of the file.                                  |
731| flags  | number | No  | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **0o200000**: If **path** does not point to a directory, throw an exception.<br><br/>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.|
732| mode   | number | No  | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o660**.<br>- **0o660**: The owner and user group have the read and write permissions.<br>- **0o640**: The owner has the read and write permissions, and the user group has the read permission.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.|
733
734**Return value**
735
736  | Type    | Description         |
737  | ------ | ----------- |
738  | number | File descriptor of the file opened.|
739
740**Example**
741
742  ```ts
743  let filePath = pathDir + "/test.txt";
744  let fd = fileio.openSync(filePath, 0o102, 0o640);
745  ```
746  ```ts
747  let filePath = pathDir + "/test.txt";
748  let fd = fileio.openSync(filePath, 0o102, 0o666);
749  fileio.writeSync(fd, 'hello world');
750  let fd1 = fileio.openSync(filePath, 0o2002);
751  fileio.writeSync(fd1, 'hello world');
752  class Option {
753    offset: number = 0;
754    length: number = 4096;
755    position: number = 0;
756  }
757  let option = new Option();
758  option.position = 0;
759  let buf = new ArrayBuffer(4096)
760  let num = fileio.readSync(fd1, buf, option);
761  console.info("num == " + num);
762  ```
763
764
765## fileio.read
766
767read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; position?: number; }): Promise&lt;ReadOut&gt;
768
769Reads data from a file. This API uses a promise to return the result.
770
771> **NOTE**
772>
773> This API is deprecated since API version 9. Use [fs.read](js-apis-file-fs.md#fsread) instead.
774
775**System capability**: SystemCapability.FileManagement.File.FileIO
776
777**Parameters**
778
779| Name | Type       | Mandatory| Description                                                        |
780| ------- | ----------- | ---- | ------------------------------------------------------------ |
781| fd      | number      | Yes  | File descriptor of the file to read.                                    |
782| buffer  | ArrayBuffer | Yes  | Buffer used to store the file data read.                          |
783| options | Object      | No  | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size|
784
785**Return value**
786
787  | Type                                | Description    |
788  | ---------------------------------- | ------ |
789  | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
790
791**Example**
792
793  ```ts
794  import { BusinessError } from '@ohos.base';
795  import buffer from '@ohos.buffer';
796  let filePath = pathDir + "/test.txt";
797  let fd = fileio.openSync(filePath, 0o2);
798  let arrayBuffer = new ArrayBuffer(4096);
799  fileio.read(fd, arrayBuffer).then((readLen: number) => {
800    console.info("Read file data successfully");
801    let buf = buffer.from(arrayBuffer, 0, readLen);
802    console.log(`The content of file: ${buf.toString()}`);
803  }).catch((err: BusinessError) => {
804    console.info("read file data failed with error:" + err);
805  });
806  ```
807
808
809## fileio.read
810
811read(fd: number, buffer: ArrayBuffer, options: { offset?: number; length?: number; position?: number; }, callback: AsyncCallback&lt;ReadOut&gt;): void
812
813Reads data from a file. This API uses an asynchronous callback to return the result.
814
815> **NOTE**
816>
817> This API is deprecated since API version 9. Use [fs.read](js-apis-file-fs.md#fsread-1) instead.
818
819**System capability**: SystemCapability.FileManagement.File.FileIO
820
821**Parameters**
822
823  | Name     | Type                                      | Mandatory  | Description                                      |
824  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
825  | fd       | number                                   | Yes   | File descriptor of the file to read.                            |
826  | buffer   | ArrayBuffer                              | Yes   | Buffer used to store the file data read.                       |
827  | options  | Object                                   | No   | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
828  | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes   | Callback invoked when the data is read asynchronously.                            |
829
830**Example**
831
832  ```ts
833  import { BusinessError } from '@ohos.base';
834  import buffer from '@ohos.buffer';
835  let filePath = pathDir + "/test.txt";
836  let fd = fileio.openSync(filePath, 0o2);
837  let arrayBuffer = new ArrayBuffer(4096);
838  fileio.read(fd, arrayBuffer, (err: BusinessError, readLen: number) => {
839    if (readLen) {
840      console.info("Read file data successfully");
841      let buf = buffer.from(arrayBuffer, 0, readLen);
842      console.info(`The content of file: ${buf.toString()}`);
843    }
844  });
845  ```
846
847
848## fileio.readSync
849
850readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; position?: number; }): number
851
852Reads data from a file. This API returns the result synchronously.
853
854> **NOTE**
855>
856> This API is deprecated since API version 9. Use [fs.readSync](js-apis-file-fs.md#fsreadsync) instead.
857
858**System capability**: SystemCapability.FileManagement.File.FileIO
859
860**Parameters**
861
862  | Name    | Type         | Mandatory  | Description                                      |
863  | ------- | ----------- | ---- | ---------------------------------------- |
864  | fd      | number      | Yes   | File descriptor of the file to read.                            |
865  | buffer  | ArrayBuffer | Yes   | Buffer used to store the file data read.                       |
866  | options | Object      | No   | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
867
868**Return value**
869
870  | Type    | Description      |
871  | ------ | -------- |
872  | number | Length of the data read.|
873
874**Example**
875
876  ```ts
877  let filePath = pathDir + "/test.txt";
878  let fd = fileio.openSync(filePath, 0o2);
879  let buf = new ArrayBuffer(4096);
880  let num = fileio.readSync(fd, buf);
881  ```
882
883
884## fileio.rmdir<sup>7+</sup>
885
886rmdir(path: string): Promise&lt;void&gt;
887
888Deletes a directory. This API uses a promise to return the result.
889
890> **NOTE**
891>
892> This API is deprecated since API version 9. Use [fs.rmdir](js-apis-file-fs.md#fsrmdir) instead.
893
894**System capability**: SystemCapability.FileManagement.File.FileIO
895
896**Parameters**
897
898| Name| Type  | Mandatory| Description                      |
899| ------ | ------ | ---- | -------------------------- |
900| path   | string | Yes  | Application sandbox path of the directory.|
901
902**Return value**
903
904  | Type                 | Description                          |
905  | ------------------- | ---------------------------- |
906  | Promise&lt;void&gt; | Promise that returns no value.|
907
908**Example**
909
910  ```ts
911  import { BusinessError } from '@ohos.base';
912  let dirPath = pathDir + '/testDir';
913  fileio.rmdir(dirPath).then(() => {
914    console.info("Directory deleted");
915  }).catch((err: BusinessError) => {
916    console.info("rmdir failed with error:" + err);
917  });
918  ```
919
920
921## fileio.rmdir<sup>7+</sup>
922
923rmdir(path: string, callback: AsyncCallback&lt;void&gt;): void
924
925Deletes a directory. This API uses an asynchronous callback to return the result.
926
927> **NOTE**
928>
929> This API is deprecated since API version 9. Use [fs.rmdir](js-apis-file-fs.md#fsrmdir-1) instead.
930
931**System capability**: SystemCapability.FileManagement.File.FileIO
932
933**Parameters**
934
935| Name  | Type                     | Mandatory| Description                      |
936| -------- | ------------------------- | ---- | -------------------------- |
937| path     | string                    | Yes  | Application sandbox path of the directory.|
938| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked when the directory is deleted asynchronously.  |
939
940**Example**
941
942  ```ts
943  import { BusinessError } from '@ohos.base';
944  let dirPath = pathDir + '/testDir';
945  fileio.rmdir(dirPath, (err: BusinessError) => {
946    // Do something.
947    console.info("Directory deleted");
948  });
949  ```
950
951
952## fileio.rmdirSync<sup>7+</sup>
953
954rmdirSync(path: string): void
955
956Deletes a directory. This API returns the result synchronously.
957
958> **NOTE**
959>
960> This API is deprecated since API version 9. Use [fs.rmdirSync](js-apis-file-fs.md#fsrmdirsync) instead.
961
962**System capability**: SystemCapability.FileManagement.File.FileIO
963
964**Parameters**
965
966| Name| Type  | Mandatory| Description                      |
967| ------ | ------ | ---- | -------------------------- |
968| path   | string | Yes  | Application sandbox path of the directory.|
969
970**Example**
971
972  ```ts
973  let dirPath = pathDir + '/testDir';
974  fileio.rmdirSync(dirPath);
975  ```
976
977
978## fileio.unlink
979
980unlink(path: string): Promise&lt;void&gt;
981
982Deletes a file. This API uses a promise to return the result.
983
984> **NOTE**
985>
986> This API is deprecated since API version 9. Use [fs.unlink](js-apis-file-fs.md#fsunlink) instead.
987
988**System capability**: SystemCapability.FileManagement.File.FileIO
989
990**Parameters**
991
992| Name| Type  | Mandatory| Description                      |
993| ------ | ------ | ---- | -------------------------- |
994| path   | string | Yes  | Application sandbox path of the file.|
995
996**Return value**
997
998  | Type                 | Description                          |
999  | ------------------- | ---------------------------- |
1000  | Promise&lt;void&gt; | Promise that returns no value.|
1001
1002**Example**
1003
1004  ```ts
1005  import { BusinessError } from '@ohos.base';
1006  let filePath = pathDir + "/test.txt";
1007  fileio.unlink(filePath).then(() => {
1008    console.info("File deleted");
1009  }).catch((error: BusinessError) => {
1010    console.info("remove file failed with error:" + error);
1011  });
1012  ```
1013
1014
1015## fileio.unlink
1016
1017unlink(path: string, callback: AsyncCallback&lt;void&gt;): void
1018
1019Deletes a file. This API uses an asynchronous callback to return the result.
1020
1021> **NOTE**
1022>
1023> This API is deprecated since API version 9. Use [fs.unlink](js-apis-file-fs.md#fsunlink-1) instead.
1024
1025**System capability**: SystemCapability.FileManagement.File.FileIO
1026
1027**Parameters**
1028
1029| Name  | Type                     | Mandatory| Description                      |
1030| -------- | ------------------------- | ---- | -------------------------- |
1031| path     | string                    | Yes  | Application sandbox path of the file.|
1032| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked immediately after the file is deleted.  |
1033
1034**Example**
1035
1036  ```ts
1037  import { BusinessError } from '@ohos.base';
1038  let filePath = pathDir + "/test.txt";
1039  fileio.unlink(filePath, (err: BusinessError) => {
1040    console.info("File deleted");
1041  });
1042  ```
1043
1044
1045## fileio.unlinkSync
1046
1047unlinkSync(path: string): void
1048
1049Deletes a file. This API returns the result synchronously.
1050
1051> **NOTE**
1052>
1053> This API is deprecated since API version 9. Use [fs.unlinkSync](js-apis-file-fs.md#fsunlinksync) instead.
1054
1055**System capability**: SystemCapability.FileManagement.File.FileIO
1056
1057**Parameters**
1058
1059| Name| Type  | Mandatory| Description                      |
1060| ------ | ------ | ---- | -------------------------- |
1061| path   | string | Yes  | Application sandbox path of the file.|
1062
1063**Example**
1064
1065  ```ts
1066  let filePath = pathDir + "/test.txt";
1067  fileio.unlinkSync(filePath);
1068  ```
1069
1070
1071## fileio.write
1072
1073write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): Promise&lt;number&gt;
1074
1075Writes data into a file. This API uses a promise to return the result.
1076
1077> **NOTE**
1078>
1079> This API is deprecated since API version 9. Use [fs.write](js-apis-file-fs.md#fswrite) instead.
1080
1081**System capability**: SystemCapability.FileManagement.File.FileIO
1082
1083**Parameters**
1084
1085  | Name    | Type                             | Mandatory  | Description                                      |
1086  | ------- | ------------------------------- | ---- | ---------------------------------------- |
1087  | fd      | number                          | Yes   | File descriptor of the file to write.                            |
1088  | buffer  | ArrayBuffer\|string | Yes   | Data to write. It can be a string or data from a buffer.                    |
1089  | options | Object                          | No   | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
1090
1091**Return value**
1092
1093  | Type                   | Description      |
1094  | --------------------- | -------- |
1095  | Promise&lt;number&gt; | Promise used to return the length of the data written.|
1096
1097**Example**
1098
1099  ```ts
1100  import { BusinessError } from '@ohos.base';
1101  let filePath = pathDir + "/test.txt";
1102  let fd = fileio.openSync(filePath, 0o100 | 0o2, 0o666);
1103  fileio.write(fd, "hello, world").then((number: number) => {
1104    console.info("write data to file succeed and size is:" + number);
1105  }).catch((err: BusinessError) => {
1106    console.info("write data to file failed with error:" + err);
1107  });
1108  ```
1109
1110
1111## fileio.write
1112
1113write(fd: number, buffer: ArrayBuffer|string, options: { offset?: number; length?: number; position?: number; encoding?: string; }, callback: AsyncCallback&lt;number&gt;): void
1114
1115Writes data into a file. This API uses an asynchronous callback to return the result.
1116
1117> **NOTE**
1118>
1119> This API is deprecated since API version 9. Use [fs.write](js-apis-file-fs.md#fswrite-1) instead.
1120
1121**System capability**: SystemCapability.FileManagement.File.FileIO
1122
1123**Parameters**
1124
1125  | Name     | Type                             | Mandatory  | Description                                      |
1126  | -------- | ------------------------------- | ---- | ---------------------------------------- |
1127  | fd       | number                          | Yes   | File descriptor of the file to write.                            |
1128  | buffer   | ArrayBuffer\|string | Yes   | Data to write. It can be a string or data from a buffer.                    |
1129  | options  | Object                          | No   | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
1130  | callback | AsyncCallback&lt;number&gt;     | Yes   | Callback invoked when the data is written asynchronously.                      |
1131
1132**Example**
1133
1134  ```ts
1135  import { BusinessError } from '@ohos.base';
1136  let filePath = pathDir + "/test.txt";
1137  let fd = fileio.openSync(filePath, 0o100 | 0o2, 0o666);
1138  fileio.write(fd, "hello, world", (err: BusinessError, bytesWritten: number) => {
1139    if (bytesWritten) {
1140      console.info("write data to file succeed and size is:" + bytesWritten);
1141    }
1142  });
1143  ```
1144
1145
1146## fileio.writeSync
1147
1148writeSync(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): number
1149
1150Writes data into a file. This API returns the result synchronously.
1151
1152> **NOTE**
1153>
1154> This API is deprecated since API version 9. Use [fs.writeSync](js-apis-file-fs.md#fswritesync) instead.
1155
1156**System capability**: SystemCapability.FileManagement.File.FileIO
1157
1158**Parameters**
1159
1160  | Name    | Type                             | Mandatory  | Description                                      |
1161  | ------- | ------------------------------- | ---- | ---------------------------------------- |
1162  | fd      | number                          | Yes   | File descriptor of the file to write.                            |
1163  | buffer  | ArrayBuffer\|string | Yes   | Data to write. It can be a string or data from a buffer.                    |
1164  | options | Object                          | No   | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
1165
1166**Return value**
1167
1168  | Type    | Description      |
1169  | ------ | -------- |
1170  | number | Length of the data written in the file.|
1171
1172**Example**
1173
1174  ```ts
1175  let filePath = pathDir + "/test.txt";
1176  let fd = fileio.openSync(filePath, 0o100 | 0o2, 0o666);
1177  let num = fileio.writeSync(fd, "hello, world");
1178  ```
1179
1180
1181## fileio.hash
1182
1183hash(path: string, algorithm: string): Promise&lt;string&gt;
1184
1185Calculates the hash value of a file. This API uses a promise to return the result.
1186
1187> **NOTE**
1188>
1189> This API is deprecated since API version 9. Use [hash.write](js-apis-file-hash.md#hashhash) instead.
1190
1191**System capability**: SystemCapability.FileManagement.File.FileIO
1192
1193**Parameters**
1194
1195| Name   | Type  | Mandatory| Description                                                        |
1196| --------- | ------ | ---- | ------------------------------------------------------------ |
1197| path      | string | Yes  | Application sandbox path of the file.                            |
1198| algorithm | string | Yes  | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.|
1199
1200**Return value**
1201
1202  | Type                   | Description                        |
1203  | --------------------- | -------------------------- |
1204| Promise&lt;string&gt; | Promise used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
1205
1206**Example**
1207
1208  ```ts
1209  import { BusinessError } from '@ohos.base';
1210  let filePath = pathDir + "/test.txt";
1211  fileio.hash(filePath, "sha256").then((str: string) => {
1212    console.info("calculate file hash succeed:" + str);
1213  }).catch((err: BusinessError) => {
1214    console.info("calculate file hash failed with error:" + err);
1215  });
1216  ```
1217
1218
1219## fileio.hash
1220
1221hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): void
1222
1223Calculates the hash value of a file. This API uses an asynchronous callback to return the result.
1224
1225> **NOTE**
1226>
1227> This API is deprecated since API version 9. Use [hash.write](js-apis-file-hash.md#hashhash-1) instead.
1228
1229**System capability**: SystemCapability.FileManagement.File.FileIO
1230
1231**Parameters**
1232
1233| Name   | Type                       | Mandatory| Description                                                        |
1234| --------- | --------------------------- | ---- | ------------------------------------------------------------ |
1235| path      | string                      | Yes  | Application sandbox path of the file.                            |
1236| algorithm | string                      | Yes  | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.|
1237| callback  | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
1238
1239**Example**
1240
1241  ```ts
1242  import { BusinessError } from '@ohos.base';
1243  let filePath = pathDir + "/test.txt";
1244  fileio.hash(filePath, "sha256", (err: BusinessError, hashStr: string) => {
1245    if (hashStr) {
1246      console.info("calculate file hash succeed:" + hashStr);
1247    }
1248  });
1249  ```
1250
1251
1252## fileio.chmod<sup>7+</sup>
1253
1254chmod(path: string, mode: number): Promise&lt;void&gt;
1255
1256Changes file permissions. This API uses a promise to return the result.
1257
1258> **NOTE**
1259>
1260> This API is deprecated since API version 9.
1261
1262**System capability**: SystemCapability.FileManagement.File.FileIO
1263
1264**Parameters**
1265
1266| Name| Type  | Mandatory| Description                                                        |
1267| ------ | ------ | ---- | ------------------------------------------------------------ |
1268| path   | string | Yes  | Application sandbox path of the file.                              |
1269| mode   | number | Yes  | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
1270
1271**Return value**
1272
1273  | Type                 | Description                          |
1274  | ------------------- | ---------------------------- |
1275  | Promise&lt;void&gt; | Promise that returns no value.|
1276
1277**Example**
1278
1279  ```ts
1280  import { BusinessError } from '@ohos.base';
1281  let filePath = pathDir + "/test.txt";
1282  fileio.chmod(filePath, 0o700).then(() => {
1283    console.info("File permissions changed");
1284  }).catch((err: BusinessError) => {
1285    console.info("chmod failed with error:" + err);
1286  });
1287  ```
1288
1289
1290## fileio.chmod<sup>7+</sup>
1291
1292chmod(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
1293
1294Changes file permissions. This API uses an asynchronous callback to return the result.
1295
1296> **NOTE**
1297>
1298> This API is deprecated since API version 9.
1299
1300**System capability**: SystemCapability.FileManagement.File.FileIO
1301
1302**Parameters**
1303
1304| Name  | Type                     | Mandatory| Description                                                        |
1305| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
1306| path     | string                    | Yes  | Application sandbox path of the file.                              |
1307| mode     | number                    | Yes  | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
1308| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked when the file permissions are changed asynchronously.                                |
1309
1310**Example**
1311
1312  ```ts
1313  import { BusinessError } from '@ohos.base';
1314  let filePath = pathDir + "/test.txt";
1315  fileio.chmod(filePath, 0o700, (err: BusinessError) => {
1316    // Do something.
1317  });
1318  ```
1319
1320
1321## fileio.chmodSync<sup>7+</sup>
1322
1323chmodSync(path: string, mode: number): void
1324
1325Changes file permissions. This API returns the result synchronously.
1326
1327> **NOTE**
1328>
1329> This API is deprecated since API version 9.
1330
1331**System capability**: SystemCapability.FileManagement.File.FileIO
1332
1333**Parameters**
1334
1335| Name| Type  | Mandatory| Description                                                        |
1336| ------ | ------ | ---- | ------------------------------------------------------------ |
1337| path   | string | Yes  | Application sandbox path of the file.                              |
1338| mode   | number | Yes  | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
1339
1340**Example**
1341
1342  ```ts
1343  let filePath = pathDir + "/test.txt";
1344  fileio.chmodSync(filePath, 0o700);
1345  ```
1346
1347
1348## fileio.fstat<sup>7+</sup>
1349
1350fstat(fd: number): Promise&lt;Stat&gt;
1351
1352Obtains file information based on the file descriptor. This API uses a promise to return the result.
1353
1354> **NOTE**
1355>
1356> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#fsstat) instead.
1357
1358**System capability**: SystemCapability.FileManagement.File.FileIO
1359
1360**Parameters**
1361
1362  | Name | Type    | Mandatory  | Description          |
1363  | ---- | ------ | ---- | ------------ |
1364  | fd   | number | Yes   | File descriptor of the target file.|
1365
1366**Return value**
1367
1368  | Type                          | Description        |
1369  | ---------------------------- | ---------- |
1370| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
1371
1372**Example**
1373
1374  ```ts
1375  import { BusinessError } from '@ohos.base';
1376  let filePath = pathDir + "/test.txt";
1377  let fd = fileio.openSync(filePath);
1378  fileio.fstat(fd).then((stat: fileio.Stat) => {
1379    console.info("fstat succeed, the size of file is " + stat.size);
1380  }).catch((err: BusinessError) => {
1381    console.info("fstat failed with error:" + err);
1382  });
1383  ```
1384
1385
1386## fileio.fstat<sup>7+</sup>
1387
1388fstat(fd: number, callback: AsyncCallback&lt;Stat&gt;): void
1389
1390Obtains file information based on the file descriptor. This API uses an asynchronous callback to return the result.
1391
1392> **NOTE**
1393>
1394> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#fsstat-1) instead.
1395
1396**System capability**: SystemCapability.FileManagement.File.FileIO
1397
1398**Parameters**
1399
1400  | Name     | Type                                | Mandatory  | Description              |
1401  | -------- | ---------------------------------- | ---- | ---------------- |
1402  | fd       | number                             | Yes   | File descriptor of the target file.    |
1403  | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes   | Callback invoked to return the file information obtained.|
1404
1405**Example**
1406
1407  ```ts
1408  import { BusinessError } from '@ohos.base';
1409  let filePath = pathDir + "/test.txt";
1410  let fd = fileio.openSync(filePath);
1411  fileio.fstat(fd, (err: BusinessError) => {
1412    // Do something.
1413  });
1414  ```
1415
1416
1417## fileio.fstatSync<sup>7+</sup>
1418
1419fstatSync(fd: number): Stat
1420
1421Obtains file status information based on the file descriptor. This API returns the result synchronously.
1422
1423> **NOTE**
1424>
1425> This API is deprecated since API version 9. Use [fs.statSync](js-apis-file-fs.md#fsstatsync) instead.
1426
1427**System capability**: SystemCapability.FileManagement.File.FileIO
1428
1429**Parameters**
1430
1431  | Name | Type    | Mandatory  | Description          |
1432  | ---- | ------ | ---- | ------------ |
1433  | fd   | number | Yes   | File descriptor of the target file.|
1434
1435**Return value**
1436
1437  | Type           | Description        |
1438  | ------------- | ---------- |
1439| [Stat](#stat) | File information obtained.|
1440
1441**Example**
1442
1443  ```ts
1444  let filePath = pathDir + "/test.txt";
1445  let fd = fileio.openSync(filePath);
1446  let stat = fileio.fstatSync(fd);
1447  ```
1448
1449
1450## fileio.ftruncate<sup>7+</sup>
1451
1452ftruncate(fd: number, len?: number): Promise&lt;void&gt;
1453
1454Truncates a file based on the file descriptor. This API uses a promise to return the result.
1455
1456> **NOTE**
1457>
1458> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate) instead.
1459
1460**System capability**: SystemCapability.FileManagement.File.FileIO
1461
1462**Parameters**
1463
1464  | Name | Type    | Mandatory  | Description              |
1465  | ---- | ------ | ---- | ---------------- |
1466  | fd   | number | Yes   | File descriptor of the file to truncate.    |
1467  | len  | number | No   | File length, in bytes, after truncation.|
1468
1469**Return value**
1470
1471  | Type                 | Description                          |
1472  | ------------------- | ---------------------------- |
1473  | Promise&lt;void&gt; | Promise that returns no value.|
1474
1475**Example**
1476
1477  ```ts
1478  import { BusinessError } from '@ohos.base';
1479  let filePath = pathDir + "/test.txt";
1480  let fd = fileio.openSync(filePath);
1481  fileio.ftruncate(fd, 5).then((err: BusinessError) => {
1482    console.info("File truncated");
1483  }).catch((err: BusinessError) => {
1484    console.info("truncate file failed with error:" + err);
1485  });
1486  ```
1487
1488
1489## fileio.ftruncate<sup>7+</sup>
1490
1491ftruncate(fd: number, len?: number, callback: AsyncCallback&lt;void&gt;): void
1492
1493Truncates a file based on the file descriptor. This API uses an asynchronous callback to return the result.
1494
1495> **NOTE**
1496>
1497> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate-1) instead.
1498
1499**System capability**: SystemCapability.FileManagement.File.FileIO
1500
1501**Parameters**
1502
1503  | Name     | Type                       | Mandatory  | Description              |
1504  | -------- | ------------------------- | ---- | ---------------- |
1505  | fd       | number                    | Yes   | File descriptor of the file to truncate.    |
1506  | len      | number                    | No   | File length, in bytes, after truncation.|
1507  | callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value. |
1508
1509**Example**
1510
1511  ```ts
1512  import { BusinessError } from '@ohos.base';
1513  let filePath = pathDir + "/test.txt";
1514  let fd = fileio.openSync(filePath);
1515  let len = 5;
1516  fileio.ftruncate(fd, 5, (err: BusinessError) => {
1517    // Do something.
1518  });
1519  ```
1520
1521
1522## fileio.ftruncateSync<sup>7+</sup>
1523
1524ftruncateSync(fd: number, len?: number): void
1525
1526Truncates a file based on the file descriptor. This API returns the result synchronously.
1527
1528> **NOTE**
1529>
1530> This API is deprecated since API version 9. Use [fs.truncateSync](js-apis-file-fs.md#fstruncatesync) instead.
1531
1532**System capability**: SystemCapability.FileManagement.File.FileIO
1533
1534**Parameters**
1535
1536  | Name | Type    | Mandatory  | Description              |
1537  | ---- | ------ | ---- | ---------------- |
1538  | fd   | number | Yes   | File descriptor of the file to truncate.    |
1539  | len  | number | No   | File length, in bytes, after truncation.|
1540
1541**Example**
1542
1543  ```ts
1544  let filePath = pathDir + "/test.txt";
1545  let fd = fileio.openSync(filePath);
1546  let len = 5;
1547  fileio.ftruncateSync(fd, len);
1548  ```
1549
1550
1551## fileio.truncate<sup>7+</sup>
1552
1553truncate(path: string, len?: number): Promise&lt;void&gt;
1554
1555Truncates a file based on the file path. This API uses a promise to return the result.
1556
1557> **NOTE**
1558>
1559> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate) instead.
1560
1561**System capability**: SystemCapability.FileManagement.File.FileIO
1562
1563**Parameters**
1564
1565| Name| Type  | Mandatory| Description                            |
1566| ------ | ------ | ---- | -------------------------------- |
1567| path   | string | Yes  | Application sandbox path of the file to truncate.      |
1568| len    | number | No  | File length, in bytes, after truncation.|
1569
1570**Return value**
1571
1572  | Type                 | Description                          |
1573  | ------------------- | ---------------------------- |
1574  | Promise&lt;void&gt; | Promise that returns no value.|
1575
1576**Example**
1577
1578  ```ts
1579  import { BusinessError } from '@ohos.base';
1580  let filePath = pathDir + "/test.txt";
1581  let len = 5;
1582  fileio.truncate(filePath, len).then(() => {
1583    console.info("File truncated");
1584  }).catch((err: BusinessError) => {
1585    console.info("truncate file failed with error:" + err);
1586  });
1587  ```
1588
1589
1590## fileio.truncate<sup>7+</sup>
1591
1592truncate(path: string, len?: number, callback: AsyncCallback&lt;void&gt;): void
1593
1594Truncates a file based on the file path. This API uses an asynchronous callback to return the result.
1595
1596> **NOTE**
1597>
1598> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate-1) instead.
1599
1600**System capability**: SystemCapability.FileManagement.File.FileIO
1601
1602**Parameters**
1603
1604| Name  | Type                     | Mandatory| Description                            |
1605| -------- | ------------------------- | ---- | -------------------------------- |
1606| path     | string                    | Yes  | Application sandbox path of the file to truncate.      |
1607| len      | number                    | No  | File length, in bytes, after truncation.|
1608| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.  |
1609
1610**Example**
1611
1612  ```ts
1613  import { BusinessError } from '@ohos.base';
1614  let filePath = pathDir + "/test.txt";
1615  let len = 5;
1616  fileio.truncate(filePath, len, (err: BusinessError) => {
1617    // Do something.
1618  });
1619  ```
1620
1621
1622## fileio.truncateSync<sup>7+</sup>
1623
1624truncateSync(path: string, len?: number): void
1625
1626Truncates a file based on the file path. This API returns the result synchronously.
1627
1628> **NOTE**
1629>
1630> This API is deprecated since API version 9. Use [fs.truncateSync](js-apis-file-fs.md#fstruncatesync) instead.
1631
1632**System capability**: SystemCapability.FileManagement.File.FileIO
1633
1634**Parameters**
1635
1636| Name| Type  | Mandatory| Description                            |
1637| ------ | ------ | ---- | -------------------------------- |
1638| path   | string | Yes  | Application sandbox path of the file to truncate.      |
1639| len    | number | No  | File length, in bytes, after truncation.|
1640
1641**Example**
1642
1643  ```ts
1644  let filePath = pathDir + "/test.txt";
1645  let len = 5;
1646  fileio.truncateSync(filePath, len);
1647  ```
1648
1649
1650## fileio.readText<sup>7+</sup>
1651
1652readText(filePath: string, options?: { position?: number; length?: number; encoding?: string; }): Promise&lt;string&gt;
1653
1654Reads the text content of a file. This API uses a promise to return the result.
1655
1656> **NOTE**
1657>
1658> This API is deprecated since API version 9. Use [fs.readText](js-apis-file-fs.md#fsreadtext) instead.
1659
1660**System capability**: SystemCapability.FileManagement.File.FileIO
1661
1662**Parameters**
1663
1664| Name  | Type  | Mandatory| Description                                                        |
1665| -------- | ------ | ---- | ------------------------------------------------------------ |
1666| filePath | string | Yes  | Application sandbox path of the file to read.                                  |
1667| options  | Object | No  | The options are as follows:<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
1668
1669**Return value**
1670
1671  | Type                   | Description        |
1672  | --------------------- | ---------- |
1673  | Promise&lt;string&gt; | Promise used to return the file content read.|
1674
1675**Example**
1676
1677  ```ts
1678  import { BusinessError } from '@ohos.base';
1679  let filePath = pathDir + "/test.txt";
1680  fileio.readText(filePath).then((str: string) => {
1681    console.info("readText succeed:" + str);
1682  }).catch((err: BusinessError) => {
1683    console.info("readText failed with error:" + err);
1684  });
1685  ```
1686
1687
1688## fileio.readText<sup>7+</sup>
1689
1690readText(filePath: string, options: { position?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;string&gt;): void
1691
1692Reads the text content of a file. This API uses an asynchronous callback to return the result.
1693
1694> **NOTE**
1695>
1696> This API is deprecated since API version 9. Use [fs.readText](js-apis-file-fs.md#fsreadtext-1) instead.
1697
1698**System capability**: SystemCapability.FileManagement.File.FileIO
1699
1700**Parameters**
1701
1702| Name  | Type                       | Mandatory| Description                                                        |
1703| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
1704| filePath | string                      | Yes  | Application sandbox path of the file to read.                                  |
1705| options  | Object                      | No  | The options are as follows:<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **encoding**: format of the data to be encoded. The default value is **utf-8**, which is the only value supported.|
1706| callback | AsyncCallback&lt;string&gt; | Yes  | Callback invoked to return the content read.                        |
1707
1708**Example**
1709
1710  ```ts
1711  import { BusinessError } from '@ohos.base';
1712  let filePath = pathDir + "/test.txt";
1713  class Option {
1714    length: number = 4096;
1715    position: number = 0;
1716    encoding: string = 'utf-8';
1717  }
1718  let option = new Option();
1719  option.position = 1;
1720  option.encoding = 'utf-8';
1721  fileio.readText(filePath, option, (err: BusinessError, str: string) => {
1722    // Do something.
1723  });
1724  ```
1725
1726
1727## fileio.readTextSync<sup>7+</sup>
1728
1729readTextSync(filePath: string, options?: { position?: number; length?: number; encoding?: string; }): string
1730
1731Reads the text of a file. This API returns the result synchronously.
1732
1733> **NOTE**
1734>
1735> This API is deprecated since API version 9. Use [fs.readTextSync](js-apis-file-fs.md#fsreadtextsync) instead.
1736
1737**System capability**: SystemCapability.FileManagement.File.FileIO
1738
1739**Parameters**
1740
1741| Name  | Type  | Mandatory| Description                                                        |
1742| -------- | ------ | ---- | ------------------------------------------------------------ |
1743| filePath | string | Yes  | Application sandbox path of the file to read.                                  |
1744| options  | Object | No  | The options are as follows:<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
1745
1746**Return value**
1747
1748  | Type  | Description                |
1749  | ------ | -------------------- |
1750  | string | File content read.|
1751
1752**Example**
1753
1754  ```ts
1755  let filePath = pathDir + "/test.txt";
1756  class Option {
1757    length: number = 4096;
1758    position: number = 0;
1759    encoding: string = 'utf-8';
1760  }
1761  let option = new Option();
1762  option.position = 1;
1763  option.length = 3;
1764  let str = fileio.readTextSync(filePath, option);
1765  ```
1766
1767
1768## fileio.lstat<sup>7+</sup>
1769
1770lstat(path: string): Promise&lt;Stat&gt;
1771
1772Obtains link information. This API uses a promise to return the result.
1773
1774> **NOTE**
1775>
1776> This API is deprecated since API version 9. Use [fs.lstat](js-apis-file-fs.md#fslstat) instead.
1777
1778**System capability**: SystemCapability.FileManagement.File.FileIO
1779
1780**Parameters**
1781
1782| Name| Type  | Mandatory| Description                                  |
1783| ------ | ------ | ---- | -------------------------------------- |
1784| path   | string | Yes  | Application sandbox path of the target file.|
1785
1786**Return value**
1787
1788  | Type                          | Description        |
1789  | ---------------------------- | ---------- |
1790  | Promise&lt;[Stat](#stat)&gt; | Promise used to return the symbolic link information obtained. For details, see **stat**.|
1791
1792**Example**
1793
1794  ```ts
1795  import { BusinessError } from '@ohos.base';
1796  let filePath = pathDir + "/test.txt";
1797  fileio.lstat(filePath).then((stat: fileio.Stat) => {
1798    console.info("get link status succeed, the size of file is" + stat.size);
1799  }).catch((err: BusinessError) => {
1800    console.info("get link status failed with error:" + err);
1801  });
1802  ```
1803
1804
1805## fileio.lstat<sup>7+</sup>
1806
1807lstat(path: string, callback: AsyncCallback&lt;Stat&gt;): void
1808
1809Obtains link information. This API uses an asynchronous callback to return the result.
1810
1811> **NOTE**
1812>
1813> This API is deprecated since API version 9. Use [fs.lstat](js-apis-file-fs.md#fslstat-1) instead.
1814
1815**System capability**: SystemCapability.FileManagement.File.FileIO
1816
1817**Parameters**
1818
1819| Name  | Type                              | Mandatory| Description                                  |
1820| -------- | ---------------------------------- | ---- | -------------------------------------- |
1821| path     | string                             | Yes  | Application sandbox path of the target file.|
1822| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes  | Callback invoked to return the symbolic link information obtained.      |
1823
1824**Example**
1825
1826  ```ts
1827  import { BusinessError } from '@ohos.base';
1828  let filePath = pathDir + "/test.txt";
1829  fileio.lstat(filePath, (err: BusinessError, stat: fileio.Stat) => {
1830    // Do something.
1831  });
1832  ```
1833
1834
1835## fileio.lstatSync<sup>7+</sup>
1836
1837lstatSync(path: string): Stat
1838
1839Obtains the link information. This API returns the result synchronously.
1840
1841> **NOTE**
1842>
1843> This API is deprecated since API version 9. Use [fs.lstatSync](js-apis-file-fs.md#fslstatsync) instead.
1844
1845**System capability**: SystemCapability.FileManagement.File.FileIO
1846
1847**Parameters**
1848
1849| Name| Type  | Mandatory| Description                                  |
1850| ------ | ------ | ---- | -------------------------------------- |
1851| path   | string | Yes  | Application sandbox path of the target file.|
1852
1853**Return value**
1854
1855  | Type           | Description        |
1856  | ------------- | ---------- |
1857  | [Stat](#stat) | Link information obtained.|
1858
1859**Example**
1860
1861  ```ts
1862  let filePath = pathDir + "/test.txt";
1863  let stat = fileio.lstatSync(filePath);
1864  ```
1865
1866
1867## fileio.rename<sup>7+</sup>
1868
1869rename(oldPath: string, newPath: string): Promise&lt;void&gt;
1870
1871Renames a file. This API uses a promise to return the result.
1872
1873> **NOTE**
1874>
1875> This API is deprecated since API version 9. Use [fs.rename](js-apis-file-fs.md#fsrename) instead.
1876
1877**System capability**: SystemCapability.FileManagement.File.FileIO
1878
1879**Parameters**
1880
1881| Name | Type  | Mandatory| Description                        |
1882| ------- | ------ | ---- | ---------------------------- |
1883| oldPath | string | Yes  | Application sandbox path of the file to rename.|
1884| newPath | string | Yes  | Application sandbox path of the file renamed.  |
1885
1886**Return value**
1887
1888  | Type                 | Description                          |
1889  | ------------------- | ---------------------------- |
1890  | Promise&lt;void&gt; | Promise that returns no value.|
1891
1892**Example**
1893
1894  ```ts
1895  import { BusinessError } from '@ohos.base';
1896  let srcFile = pathDir + "/test.txt";
1897  let dstFile = pathDir + '/new.txt';
1898  fileio.rename(srcFile, dstFile).then(() => {
1899    console.info("File renamed");
1900  }).catch((err: BusinessError) => {
1901    console.info("rename failed with error:" + err);
1902  });
1903  ```
1904
1905
1906## fileio.rename<sup>7+</sup>
1907
1908rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void
1909
1910Renames a file. This API uses an asynchronous callback to return the result.
1911
1912> **NOTE**
1913>
1914> This API is deprecated since API version 9. Use [fs.rename](js-apis-file-fs.md#fsrename-1) instead.
1915
1916**System capability**: SystemCapability.FileManagement.File.FileIO
1917
1918**Parameters**
1919
1920| Name  | Type                     | Mandatory| Description                        |
1921| -------- | ------------------------- | ---- | ---------------------------- |
1922| oldPath  | string                    | Yes  | Application sandbox path of the file to rename.|
1923| newPath  | string                    | Yes  | Application sandbox path of the file renamed.  |
1924| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked when the file is asynchronously renamed.  |
1925
1926**Example**
1927
1928  ```ts
1929  import { BusinessError } from '@ohos.base';
1930  let srcFile = pathDir + "/test.txt";
1931  let dstFile = pathDir + '/new.txt';
1932  fileio.rename(srcFile, dstFile, (err: BusinessError) => {
1933  });
1934  ```
1935
1936## fileio.renameSync<sup>7+</sup>
1937
1938renameSync(oldPath: string, newPath: string): void
1939
1940Renames a file. This API returns the result synchronously.
1941
1942> **NOTE**
1943>
1944> This API is deprecated since API version 9. Use [fs.renameSync](js-apis-file-fs.md#fsrenamesync) instead.
1945
1946**System capability**: SystemCapability.FileManagement.File.FileIO
1947
1948**Parameters**
1949
1950| Name | Type  | Mandatory| Description                        |
1951| ------- | ------ | ---- | ---------------------------- |
1952| oldPath | string | Yes  | Application sandbox path of the file to rename.|
1953| newPath | string | Yes  | Application sandbox path of the file renamed.  |
1954
1955**Example**
1956
1957  ```ts
1958  let srcFile = pathDir + "/test.txt";
1959  let dstFile = pathDir + '/new.txt';
1960  fileio.renameSync(srcFile, dstFile);
1961  ```
1962
1963
1964## fileio.fsync<sup>7+</sup>
1965
1966fsync(fd: number): Promise&lt;void&gt;
1967
1968Flushes data of a file to disk. This API uses a promise to return the result.
1969
1970> **NOTE**
1971>
1972> This API is deprecated since API version 9. Use [fs.fsync](js-apis-file-fs.md#fsfsync) instead.
1973
1974**System capability**: SystemCapability.FileManagement.File.FileIO
1975
1976**Parameters**
1977
1978  | Name | Type    | Mandatory  | Description          |
1979  | ---- | ------ | ---- | ------------ |
1980  | fd   | number | Yes   | File descriptor of the file to flush.|
1981
1982**Return value**
1983
1984  | Type                 | Description                          |
1985  | ------------------- | ---------------------------- |
1986  | Promise&lt;void&gt; | Promise that returns no value.|
1987
1988**Example**
1989
1990  ```ts
1991  import { BusinessError } from '@ohos.base';
1992  let filePath = pathDir + "/test.txt";
1993  let fd = fileio.openSync(filePath);
1994  fileio.fsync(fd).then(() => {
1995    console.info("Data flushed");
1996  }).catch((err: BusinessError) => {
1997    console.info("sync data failed with error:" + err);
1998  });
1999  ```
2000
2001
2002## fileio.fsync<sup>7+</sup>
2003
2004fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void
2005
2006Flushes data of a file to disk. This API uses an asynchronous callback to return the result.
2007
2008> **NOTE**
2009>
2010> This API is deprecated since API version 9. Use [fs.fsync](js-apis-file-fs.md#fsfsync-1) instead.
2011
2012**System capability**: SystemCapability.FileManagement.File.FileIO
2013
2014**Parameters**
2015
2016  | Name     | Type                       | Mandatory  | Description             |
2017  | -------- | ------------------------- | ---- | --------------- |
2018  | fd       | number                    | Yes   | File descriptor of the file to flush.   |
2019  | Callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the file data is synchronized in asynchronous mode.|
2020
2021**Example**
2022
2023  ```ts
2024  import { BusinessError } from '@ohos.base';
2025  let filePath = pathDir + "/test.txt";
2026  let fd = fileio.openSync(filePath);
2027  fileio.fsync(fd, (err: BusinessError) => {
2028    // Do something.
2029  });
2030  ```
2031
2032
2033## fileio.fsyncSync<sup>7+</sup>
2034
2035fsyncSync(fd: number): void
2036
2037Flushes data of a file to disk synchronously.
2038
2039> **NOTE**
2040>
2041> This API is deprecated since API version 9. Use [fs.fsyncSync](js-apis-file-fs.md#fsfsyncsync) instead.
2042
2043**System capability**: SystemCapability.FileManagement.File.FileIO
2044
2045**Parameters**
2046
2047  | Name | Type    | Mandatory  | Description          |
2048  | ---- | ------ | ---- | ------------ |
2049  | fd   | number | Yes   | File descriptor of the file to flush.|
2050
2051**Example**
2052
2053  ```ts
2054  let filePath = pathDir + "/test.txt";
2055  let fd = fileio.openSync(filePath);
2056  fileio.fsyncSync(fd);
2057  ```
2058
2059
2060## fileio.fdatasync<sup>7+</sup>
2061
2062fdatasync(fd: number): Promise&lt;void&gt;
2063
2064Flushes data of a file to disk. This API uses a promise to return the result. **fdatasync()** is similar to **fsync()**, but does not flush modified metadata unless that metadata is needed.
2065
2066> **NOTE**
2067>
2068> This API is deprecated since API version 9. Use [fs.fdatasync](js-apis-file-fs.md#fsfdatasync) instead.
2069
2070**System capability**: SystemCapability.FileManagement.File.FileIO
2071
2072**Parameters**
2073
2074  | Name | Type    | Mandatory  | Description          |
2075  | ---- | ------ | ---- | ------------ |
2076  | fd   | number | Yes   | File descriptor of the file to flush.|
2077
2078**Return value**
2079
2080  | Type                 | Description                          |
2081  | ------------------- | ---------------------------- |
2082  | Promise&lt;void&gt; | Promise that returns no value.|
2083
2084**Example**
2085
2086  ```ts
2087  import { BusinessError } from '@ohos.base';
2088  let filePath = pathDir + "/test.txt";
2089  let fd = fileio.openSync(filePath);
2090  fileio.fdatasync(fd).then((err: BusinessError) => {
2091    console.info("Data flushed");
2092  }).catch((err: BusinessError) => {
2093    console.info("sync data failed with error:" + err);
2094  });
2095  ```
2096
2097
2098## fileio.fdatasync<sup>7+</sup>
2099
2100fdatasync(fd: number, callback: AsyncCallback&lt;void&gt;): void
2101
2102Flushes data of a file to disk. This API uses an asynchronous callback to return the result.
2103
2104> **NOTE**
2105>
2106> This API is deprecated since API version 9. Use [fs.fdatasync](js-apis-file-fs.md#fsfdatasync-1) instead.
2107
2108**System capability**: SystemCapability.FileManagement.File.FileIO
2109
2110**Parameters**
2111
2112  | Name     | Type                             | Mandatory  | Description               |
2113  | -------- | ------------------------------- | ---- | ----------------- |
2114  | fd       | number                          | Yes   | File descriptor of the file to synchronize.     |
2115  | callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the file data is synchronized in asynchronous mode.|
2116
2117**Example**
2118
2119  ```ts
2120  import { BusinessError } from '@ohos.base';
2121  let filePath = pathDir + "/test.txt";
2122  let fd = fileio.openSync(filePath);
2123  fileio.fdatasync (fd, (err: BusinessError) => {
2124    // Do something.
2125  });
2126  ```
2127
2128
2129## fileio.fdatasyncSync<sup>7+</sup>
2130
2131fdatasyncSync(fd: number): void
2132
2133Synchronizes data in a file synchronously.
2134
2135> **NOTE**
2136>
2137> This API is deprecated since API version 9. Use [fs.fdatasyncSync](js-apis-file-fs.md#fsfdatasyncsync) instead.
2138
2139**System capability**: SystemCapability.FileManagement.File.FileIO
2140
2141**Parameters**
2142
2143  | Name | Type    | Mandatory  | Description          |
2144  | ---- | ------ | ---- | ------------ |
2145  | fd   | number | Yes   | File descriptor of the file to flush.|
2146
2147**Example**
2148
2149  ```ts
2150  let filePath = pathDir + "/test.txt";
2151  let fd = fileio.openSync(filePath);
2152  let stat = fileio.fdatasyncSync(fd);
2153  ```
2154
2155
2156## fileio.symlink<sup>7+</sup>
2157
2158symlink(target: string, srcPath: string): Promise&lt;void&gt;
2159
2160Creates a symbolic link based on the file path. This API uses a promise to return the result.
2161
2162> **NOTE**
2163>
2164> This API is deprecated since API version 9. Use [fs.symlink](js-apis-file-fs.md#fssymlink) instead.
2165
2166**System capability**: SystemCapability.FileManagement.File.FileIO
2167
2168**Parameters**
2169
2170| Name | Type  | Mandatory| Description                        |
2171| ------- | ------ | ---- | ---------------------------- |
2172| target  | string | Yes  | Application sandbox path of the target file.    |
2173| srcPath | string | Yes  | Application sandbox path of the symbolic link.|
2174
2175**Return value**
2176
2177  | Type                 | Description                          |
2178  | ------------------- | ---------------------------- |
2179  | Promise&lt;void&gt; | Promise that returns no value.|
2180
2181**Example**
2182
2183  ```ts
2184  import { BusinessError } from '@ohos.base';
2185  let srcFile = pathDir + "/test.txt";
2186  let dstFile = pathDir + '/test';
2187  fileio.symlink(srcFile, dstFile).then(() => {
2188    console.info("Symbolic link created");
2189  }).catch((err: BusinessError) => {
2190    console.info("symlink failed with error:" + err);
2191  });
2192  ```
2193
2194
2195## fileio.symlink<sup>7+</sup>
2196
2197symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): void
2198
2199Creates a symbolic link based on the file path. This API uses an asynchronous callback to return the result.
2200
2201> **NOTE**
2202>
2203> This API is deprecated since API version 9. Use [fs.symlink](js-apis-file-fs.md#fssymlink-1) instead.
2204
2205**System capability**: SystemCapability.FileManagement.File.FileIO
2206
2207**Parameters**
2208
2209| Name  | Type                     | Mandatory| Description                            |
2210| -------- | ------------------------- | ---- | -------------------------------- |
2211| target   | string                    | Yes  | Application sandbox path of the target file.        |
2212| srcPath  | string                    | Yes  | Application sandbox path of the symbolic link.    |
2213| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked when the symbolic link is created asynchronously.|
2214
2215**Example**
2216
2217  ```ts
2218  import { BusinessError } from '@ohos.base';
2219  let srcFile = pathDir + "/test.txt";
2220  let dstFile = pathDir + '/test';
2221  fileio.symlink(srcFile, dstFile, (err: BusinessError) => {
2222    // Do something.
2223  });
2224  ```
2225
2226
2227## fileio.symlinkSync<sup>7+</sup>
2228
2229symlinkSync(target: string, srcPath: string): void
2230
2231Creates a symbolic link based on a file path. This API returns the result synchronously.
2232
2233> **NOTE**
2234>
2235> This API is deprecated since API version 9. Use [fs.symlinkSync](js-apis-file-fs.md#fssymlinksync) instead.
2236
2237**System capability**: SystemCapability.FileManagement.File.FileIO
2238
2239**Parameters**
2240
2241| Name | Type  | Mandatory| Description                        |
2242| ------- | ------ | ---- | ---------------------------- |
2243| target  | string | Yes  | Application sandbox path of the target file.    |
2244| srcPath | string | Yes  | Application sandbox path of the symbolic link.|
2245
2246**Example**
2247
2248  ```ts
2249  let srcFile = pathDir + "/test.txt";
2250  let dstFile = pathDir + '/test';
2251  fileio.symlinkSync(srcFile, dstFile);
2252  ```
2253
2254
2255## fileio.chown<sup>7+</sup>
2256
2257chown(path: string, uid: number, gid: number): Promise&lt;void&gt;
2258
2259Changes the file owner based on the file path. This API uses a promise to return the result.
2260
2261> **NOTE**
2262>
2263> This API is deprecated since API version 9.
2264
2265**System capability**: SystemCapability.FileManagement.File.FileIO
2266
2267**Parameters**
2268
2269| Name| Type  | Mandatory| Description                      |
2270| ------ | ------ | ---- | -------------------------- |
2271| path   | string | Yes  | Application sandbox path of the file.|
2272| uid    | number | Yes  | New user ID (UID).       |
2273| gid    | number | Yes  | New group ID (GID).      |
2274
2275**Return value**
2276
2277  | Type                 | Description                          |
2278  | ------------------- | ---------------------------- |
2279  | Promise&lt;void&gt; | Promise that returns no value.|
2280
2281**Example**
2282
2283  ```ts
2284  import { BusinessError } from '@ohos.base';
2285  let filePath = pathDir + "/test.txt";
2286  let stat = fileio.statSync(filePath);
2287  fileio.chown(filePath, stat.uid, stat.gid).then(() => {
2288    console.info("File owner changed");
2289  }).catch((err: BusinessError) => {
2290    console.info("chown failed with error:" + err);
2291  });
2292  ```
2293
2294
2295## fileio.chown<sup>7+</sup>
2296
2297chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void
2298
2299Changes the file owner based on the file path. This API uses an asynchronous callback to return the result.
2300
2301> **NOTE**
2302>
2303> This API is deprecated since API version 9.
2304
2305**System capability**: SystemCapability.FileManagement.File.FileIO
2306
2307**Parameters**
2308
2309| Name  | Type                     | Mandatory| Description                          |
2310| -------- | ------------------------- | ---- | ------------------------------ |
2311| path     | string                    | Yes  | Application sandbox path of the file.    |
2312| uid      | number                    | Yes  | New UID.                     |
2313| gid      | number                    | Yes  | New GID.                     |
2314| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked when the file owner is changed asynchronously.|
2315
2316**Example**
2317
2318  ```ts
2319  import { BusinessError } from '@ohos.base';
2320  let filePath = pathDir + "/test.txt";
2321  let stat = fileio.statSync(filePath)
2322  fileio.chown(filePath, stat.uid, stat.gid, (err: BusinessError) => {
2323    // Do something.
2324  });
2325  ```
2326
2327## fileio.chownSync<sup>7+</sup>
2328
2329chownSync(path: string, uid: number, gid: number): void
2330
2331Changes the file owner based on its path. This API returns the result synchronously.
2332
2333> **NOTE**
2334>
2335> This API is deprecated since API version 9.
2336
2337**System capability**: SystemCapability.FileManagement.File.FileIO
2338
2339**Parameters**
2340
2341| Name| Type  | Mandatory| Description                      |
2342| ------ | ------ | ---- | -------------------------- |
2343| path   | string | Yes  | Application sandbox path of the file.|
2344| uid    | number | Yes  | New UID.                 |
2345| gid    | number | Yes  | New GID.                 |
2346
2347**Example**
2348
2349  ```ts
2350  let filePath = pathDir + "/test.txt";
2351  let stat = fileio.statSync(filePath)
2352  fileio.chownSync(filePath, stat.uid, stat.gid);
2353  ```
2354
2355
2356## fileio.mkdtemp<sup>7+</sup>
2357
2358mkdtemp(prefix: string): Promise&lt;string&gt;
2359
2360Creates a temporary directory. This API uses a promise to return the result.
2361
2362> **NOTE**
2363>
2364> This API is deprecated since API version 9. Use [fs.mkdtemp](js-apis-file-fs.md#fsmkdtemp) instead.
2365
2366**System capability**: SystemCapability.FileManagement.File.FileIO
2367
2368**Parameters**
2369
2370  | Name   | Type    | Mandatory  | Description                         |
2371  | ------ | ------ | ---- | --------------------------- |
2372  | prefix | string | Yes   | A randomly generated string used to replace "XXXXXX" in a directory.|
2373
2374**Return value**
2375
2376  | Type                  | Description        |
2377  | --------------------- | ---------- |
2378| Promise&lt;string&gt; | Promise used to return the unique directory generated.|
2379
2380**Example**
2381
2382  ```ts
2383  import { BusinessError } from '@ohos.base';
2384  fileio.mkdtemp(pathDir + "/XXXXXX").then((pathDir: string) => {
2385    console.info("mkdtemp succeed:" + pathDir);
2386  }).catch((err: BusinessError) => {
2387    console.info("mkdtemp failed with error:" + err);
2388  });
2389  ```
2390
2391
2392## fileio.mkdtemp<sup>7+</sup>
2393
2394mkdtemp(prefix: string, callback: AsyncCallback&lt;string&gt;): void
2395
2396Creates a temporary directory. This API uses an asynchronous callback to return the result.
2397
2398> **NOTE**
2399>
2400> This API is deprecated since API version 9. Use [fs.mkdtemp](js-apis-file-fs.md#fsmkdtemp-1) instead.
2401
2402**System capability**: SystemCapability.FileManagement.File.FileIO
2403
2404**Parameters**
2405
2406  | Name     | Type                         | Mandatory  | Description                         |
2407  | -------- | --------------------------- | ---- | --------------------------- |
2408  | prefix   | string                      | Yes   | A randomly generated string used to replace "XXXXXX" in a directory.|
2409  | callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked when a temporary directory is created asynchronously.             |
2410
2411**Example**
2412
2413  ```ts
2414  import { BusinessError } from '@ohos.base';
2415  fileio.mkdtemp(pathDir + "/XXXXXX", (err: BusinessError, res: string) {
2416    // Do something.
2417  });
2418  ```
2419
2420
2421## fileio.mkdtempSync<sup>7+</sup>
2422
2423mkdtempSync(prefix: string): string
2424
2425Creates a temporary directory. This API returns the result synchronously.
2426
2427> **NOTE**
2428>
2429> This API is deprecated since API version 9. Use [fs.mkdtempSync](js-apis-file-fs.md#fsmkdtempsync) instead.
2430
2431**System capability**: SystemCapability.FileManagement.File.FileIO
2432
2433**Parameters**
2434
2435  | Name   | Type    | Mandatory  | Description                         |
2436  | ------ | ------ | ---- | --------------------------- |
2437  | prefix | string | Yes   | A randomly generated string used to replace "XXXXXX" in a directory.|
2438
2439**Return value**
2440
2441  | Type   | Description        |
2442  | ------ | ---------- |
2443  | string | Unique path generated.|
2444
2445**Example**
2446
2447  ```ts
2448  let res = fileio.mkdtempSync(pathDir + "/XXXXXX");
2449  ```
2450
2451
2452## fileio.fchmod<sup>7+</sup>
2453
2454fchmod(fd: number, mode: number): Promise&lt;void&gt;
2455
2456Changes file permissions based on the file descriptor. This API uses a promise to return the result.
2457
2458> **NOTE**
2459>
2460> This API is deprecated since API version 9.
2461
2462**System capability**: SystemCapability.FileManagement.File.FileIO
2463
2464**Parameters**
2465
2466  | Name | Type    | Mandatory  | Description                                      |
2467  | ---- | ------ | ---- | ---------------------------------------- |
2468  | fd   | number | Yes   | File descriptor of the target file.                            |
2469  | mode | number | Yes   | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
2470
2471**Return value**
2472
2473  | Type                | Description                          |
2474  | ------------------- | ---------------------------- |
2475  | Promise&lt;void&gt; | Promise that returns no value.|
2476
2477**Example**
2478
2479  ```ts
2480  import { BusinessError } from '@ohos.base';
2481  let filePath = pathDir + "/test.txt";
2482  let fd = fileio.openSync(filePath);
2483  let mode: number = 0o700;
2484  fileio.fchmod(fd, mode).then(() => {
2485    console.info("File permissions changed");
2486  }).catch((err: BusinessError) => {
2487    console.info("chmod failed with error:" + err);
2488  });
2489  ```
2490
2491
2492## fileio.fchmod<sup>7+</sup>
2493
2494fchmod(fd: number, mode: number, callback: AsyncCallback&lt;void&gt;): void
2495
2496Changes file permissions based on the file descriptor. This API uses an asynchronous callback to return the result.
2497
2498> **NOTE**
2499>
2500> This API is deprecated since API version 9.
2501
2502**System capability**: SystemCapability.FileManagement.File.FileIO
2503
2504**Parameters**
2505
2506  | Name     | Type                             | Mandatory  | Description                                      |
2507  | -------- | ------------------------------- | ---- | ---------------------------------------- |
2508  | fd       | number                          | Yes   | File descriptor of the target file.                            |
2509  | mode     | number                          | Yes   | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
2510  | callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the file permissions are changed asynchronously.                          |
2511
2512**Example**
2513
2514  ```ts
2515  import { BusinessError } from '@ohos.base';
2516  let filePath = pathDir + "/test.txt";
2517  let fd = fileio.openSync(filePath);
2518  let mode: number = 0o700;
2519  fileio.fchmod(fd, mode, (err: BusinessError) => {
2520    // Do something.
2521  });
2522  ```
2523
2524
2525## fileio.fchmodSync<sup>7+</sup>
2526
2527fchmodSync(fd: number, mode: number): void
2528
2529Changes the file permissions based on the file descriptor. This API returns the result synchronously.
2530
2531> **NOTE**
2532>
2533> This API is deprecated since API version 9.
2534
2535**System capability**: SystemCapability.FileManagement.File.FileIO
2536
2537**Parameters**
2538
2539  | Name | Type    | Mandatory  | Description                                      |
2540  | ---- | ------ | ---- | ---------------------------------------- |
2541  | fd   | number | Yes   | File descriptor of the target file.                            |
2542  | mode | number | Yes   | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
2543
2544**Example**
2545
2546  ```ts
2547  let filePath = pathDir + "/test.txt";
2548  let fd = fileio.openSync(filePath);
2549  let mode: number = 0o700;
2550  fileio.fchmodSync(fd, mode);
2551  ```
2552
2553
2554## fileio.createStream<sup>7+</sup>
2555
2556createStream(path: string, mode: string): Promise&lt;Stream&gt;
2557
2558Creates a stream based on the file path. This API uses a promise to return the result.
2559
2560> **NOTE**
2561>
2562> This API is deprecated since API version 9. Use [fs.createStream](js-apis-file-fs.md#fscreatestream) instead.
2563
2564**System capability**: SystemCapability.FileManagement.File.FileIO
2565
2566**Parameters**
2567
2568| Name| Type  | Mandatory| Description                                                        |
2569| ------ | ------ | ---- | ------------------------------------------------------------ |
2570| path   | string | Yes  | Application sandbox path of the file.                                  |
2571| mode   | string | Yes  | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
2572
2573**Return value**
2574
2575  | Type                               | Description       |
2576  | --------------------------------- | --------- |
2577  | Promise&lt;[Stream](#stream)&gt; | Promise used to return the stream opened.|
2578
2579**Example**
2580
2581  ```ts
2582  import { BusinessError } from '@ohos.base';
2583  let filePath = pathDir + "/test.txt";
2584  fileio.createStream(filePath, "r+").then((stream: fileio.Stream) => {
2585    console.info("Stream created");
2586  }).catch((err: BusinessError) => {
2587    console.info("createStream failed with error:" + err);
2588  });
2589  ```
2590
2591
2592## fileio.createStream<sup>7+</sup>
2593
2594createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
2595
2596Creates a stream based on the file path. This API uses an asynchronous callback to return the result.
2597
2598> **NOTE**
2599>
2600> This API is deprecated since API version 9. Use [fs.createStream](js-apis-file-fs.md#fscreatestream-1) instead.
2601
2602**System capability**: SystemCapability.FileManagement.File.FileIO
2603
2604**Parameters**
2605
2606| Name  | Type                                   | Mandatory| Description                                                        |
2607| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
2608| path     | string                                  | Yes  | Application sandbox path of the file.                                  |
2609| mode     | string                                  | Yes  | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
2610| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes  | Callback invoked when the stream is created asynchronously.                                  |
2611
2612**Example**
2613
2614  ```ts
2615  import { BusinessError } from '@ohos.base';
2616  let filePath = pathDir + "/test.txt";
2617  fileio.createStream(filePath, "r+", (err: BusinessError, stream: fileio.Stream) {
2618    // Do something.
2619  });
2620  ```
2621
2622
2623## fileio.createStreamSync<sup>7+</sup>
2624
2625createStreamSync(path: string, mode: string): Stream
2626
2627Creates a stream based on the file path. This API returns the result synchronously.
2628
2629> **NOTE**
2630>
2631> This API is deprecated since API version 9. Use [fs.createStreamSync](js-apis-file-fs.md#fscreatestreamsync) instead.
2632
2633**System capability**: SystemCapability.FileManagement.File.FileIO
2634
2635**Parameters**
2636
2637| Name| Type  | Mandatory| Description                                                        |
2638| ------ | ------ | ---- | ------------------------------------------------------------ |
2639| path   | string | Yes  | Application sandbox path of the file.                                  |
2640| mode   | string | Yes  | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
2641
2642**Return value**
2643
2644  | Type               | Description       |
2645  | ------------------ | --------- |
2646| [Stream](#stream) | Stream created.|
2647
2648**Example**
2649
2650  ```ts
2651  let filePath = pathDir + "/test.txt";
2652  let ss = fileio.createStreamSync(filePath, "r+");
2653  ```
2654
2655
2656## fileio.fdopenStream<sup>7+</sup>
2657
2658fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;
2659
2660Opens a stream based on the file descriptor. This API uses a promise to return the result.
2661
2662> **NOTE**
2663>
2664> This API is deprecated since API version 9. Use [fs.fdopenStream](js-apis-file-fs.md#fsfdopenstream) instead.
2665
2666**System capability**: SystemCapability.FileManagement.File.FileIO
2667
2668**Parameters**
2669
2670  | Name | Type    | Mandatory  | Description                                      |
2671  | ---- | ------ | ---- | ---------------------------------------- |
2672  | fd   | number | Yes   | File descriptor of the target file.                            |
2673  | mode | string | Yes   | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
2674
2675**Return value**
2676
2677  | Type                              | Description       |
2678  | --------------------------------- | --------- |
2679  | Promise&lt;[Stream](#stream)&gt; | Promise used to return the stream opened.|
2680
2681**Example**
2682
2683  ```ts
2684  import { BusinessError } from '@ohos.base';
2685  let filePath = pathDir + "/test.txt";
2686  let fd = fileio.openSync(filePath);
2687  fileio.fdopenStream(fd, "r+").then((stream: fileio.Stream) => {
2688    console.info("Stream opened");
2689  }).catch((err: BusinessError) => {
2690    console.info("openStream failed with error:" + err);
2691  });
2692  ```
2693
2694
2695## fileio.fdopenStream<sup>7+</sup>
2696
2697fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
2698
2699Opens a stream based on the file descriptor. This API uses an asynchronous callback to return the result.
2700
2701> **NOTE**
2702>
2703> This API is deprecated since API version 9. Use [fs.fdopenStream](js-apis-file-fs.md#fsfdopenstream-1) instead.
2704
2705**System capability**: SystemCapability.FileManagement.File.FileIO
2706
2707**Parameters**
2708
2709  | Name     | Type                                      | Mandatory  | Description                                      |
2710  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2711  | fd       | number                                   | Yes   | File descriptor of the target file.                            |
2712  | mode     | string                                   | Yes   | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
2713| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes   | Callback invoked when the stream is open asynchronously.                           |
2714
2715**Example**
2716
2717  ```ts
2718  import { BusinessError } from '@ohos.base';
2719  let filePath = pathDir + "/test.txt";
2720  let fd = fileio.openSync(filePath);
2721  fileio.fdopenStream(fd, "r+", (err: BusinessError, stream: fileio.Stream) => {
2722    // Do something.
2723  });
2724  ```
2725
2726
2727## fileio.fdopenStreamSync<sup>7+</sup>
2728
2729fdopenStreamSync(fd: number, mode: string): Stream
2730
2731Opens a stream based on the file descriptor. This API returns the result synchronously.
2732
2733> **NOTE**
2734>
2735> This API is deprecated since API version 9. Use [fs.fdopenStreamSync](js-apis-file-fs.md#fsfdopenstreamsync) instead.
2736
2737**System capability**: SystemCapability.FileManagement.File.FileIO
2738
2739**Parameters**
2740
2741  | Name | Type    | Mandatory  | Description                                      |
2742  | ---- | ------ | ---- | ---------------------------------------- |
2743  | fd   | number | Yes   | File descriptor of the target file.                            |
2744  | mode | string | Yes   | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
2745
2746**Return value**
2747
2748  | Type               | Description       |
2749  | ------------------ | --------- |
2750  | [Stream](#stream) | Stream opened.|
2751
2752**Example**
2753
2754  ```ts
2755  let filePath = pathDir + "/test.txt";
2756  let fd = fileio.openSync(filePath);
2757  let ss = fileio.fdopenStreamSync(fd, "r+");
2758  ```
2759
2760
2761## fileio.fchown<sup>7+</sup>
2762
2763fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt;
2764
2765Changes the file owner based on the file descriptor. This API uses a promise to return the result.
2766
2767> **NOTE**
2768>
2769> This API is deprecated since API version 9.
2770
2771**System capability**: SystemCapability.FileManagement.File.FileIO
2772
2773**Parameters**
2774
2775  | Name | Type    | Mandatory  | Description          |
2776  | ---- | ------ | ---- | ------------ |
2777  | fd   | number | Yes   | File descriptor of the target file.|
2778  | uid  | number | Yes   | New UID.  |
2779  | gid  | number | Yes   | New GID.  |
2780
2781**Return value**
2782
2783  | Type                 | Description                          |
2784  | ------------------- | ---------------------------- |
2785  | Promise&lt;void&gt; | Promise that returns no value.|
2786
2787**Example**
2788
2789  ```ts
2790  import { BusinessError } from '@ohos.base';
2791  let filePath = pathDir + "/test.txt";
2792  let fd = fileio.openSync(filePath);
2793  let stat = fileio.statSync(filePath);
2794  fileio.fchown(fd, stat.uid, stat.gid).then(() => {
2795    console.info("File owner changed");
2796  }).catch((err: BusinessError) => {
2797    console.info("chown failed with error:" + err);
2798  });
2799  ```
2800
2801
2802## fileio.fchown<sup>7+</sup>
2803
2804fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void
2805
2806Changes the file owner based on the file descriptor. This API uses an asynchronous callback to return the result.
2807
2808> **NOTE**
2809>
2810> This API is deprecated since API version 9.
2811
2812**System capability**: SystemCapability.FileManagement.File.FileIO
2813
2814**Parameters**
2815
2816  | Name     | Type                       | Mandatory  | Description             |
2817  | -------- | ------------------------- | ---- | --------------- |
2818  | fd       | number                    | Yes   | File descriptor of the target file.   |
2819  | uid      | number                    | Yes   | New UID.     |
2820  | gid      | number                    | Yes   | New GID.     |
2821  | callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the file owner is changed asynchronously.|
2822
2823**Example**
2824
2825  ```ts
2826  import { BusinessError } from '@ohos.base';
2827  let filePath = pathDir + "/test.txt";
2828  let fd = fileio.openSync(filePath);
2829  let stat = fileio.statSync(filePath);
2830  fileio.fchown(fd, stat.uid, stat.gid, (err: BusinessError) => {
2831    // Do something.
2832  });
2833  ```
2834
2835
2836## fileio.fchownSync<sup>7+</sup>
2837
2838fchownSync(fd: number, uid: number, gid: number): void
2839
2840Changes the file owner based on the file descriptor. This API returns the result synchronously.
2841
2842> **NOTE**
2843>
2844> This API is deprecated since API version 9.
2845
2846**System capability**: SystemCapability.FileManagement.File.FileIO
2847
2848**Parameters**
2849
2850  | Name | Type    | Mandatory  | Description          |
2851  | ---- | ------ | ---- | ------------ |
2852  | fd   | number | Yes   | File descriptor of the target file.|
2853  | uid  | number | Yes   | New UID.  |
2854  | gid  | number | Yes   | New GID.  |
2855
2856**Example**
2857
2858  ```ts
2859  let filePath = pathDir + "/test.txt";
2860  let fd = fileio.openSync(filePath);
2861  let stat = fileio.statSync(filePath);
2862  fileio.fchownSync(fd, stat.uid, stat.gid);
2863  ```
2864
2865
2866## fileio.lchown<sup>7+</sup>
2867
2868lchown(path: string, uid: number, gid: number): Promise&lt;void&gt;
2869
2870Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on the file path. This API uses a promise to return the result.
2871
2872> **NOTE**
2873>
2874> This API is deprecated since API version 9.
2875
2876**System capability**: SystemCapability.FileManagement.File.FileIO
2877
2878**Parameters**
2879
2880| Name| Type  | Mandatory| Description                      |
2881| ------ | ------ | ---- | -------------------------- |
2882| path   | string | Yes  | Application sandbox path of the file.|
2883| uid    | number | Yes  | New UID.                 |
2884| gid    | number | Yes  | New GID.                 |
2885
2886**Return value**
2887
2888  | Type                 | Description                          |
2889  | ------------------- | ---------------------------- |
2890  | Promise&lt;void&gt; | Promise that returns no value.|
2891
2892**Example**
2893
2894  ```ts
2895  import { BusinessError } from '@ohos.base';
2896  let filePath = pathDir + "/test.txt";
2897  let stat = fileio.statSync(filePath);
2898  fileio.lchown(filePath, stat.uid, stat.gid).then(() => {
2899    console.info("File owner changed");
2900  }).catch((err: BusinessError) => {
2901    console.info("chown failed with error:" + err);
2902  });
2903  ```
2904
2905
2906## fileio.lchown<sup>7+</sup>
2907
2908lchown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void
2909
2910Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on the file path. This API uses an asynchronous callback to return the result.
2911
2912> **NOTE**
2913>
2914> This API is deprecated since API version 9.
2915
2916**System capability**: SystemCapability.FileManagement.File.FileIO
2917
2918**Parameters**
2919
2920| Name  | Type                     | Mandatory| Description                          |
2921| -------- | ------------------------- | ---- | ------------------------------ |
2922| path     | string                    | Yes  | Application sandbox path of the file.    |
2923| uid      | number                    | Yes  | New UID.                     |
2924| gid      | number                    | Yes  | New GID.                     |
2925| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked when the file owner is changed asynchronously.|
2926
2927**Example**
2928
2929  ```ts
2930  import { BusinessError } from '@ohos.base';
2931  let filePath = pathDir + "/test.txt";
2932  let stat = fileio.statSync(filePath);
2933  fileio.lchown(filePath, stat.uid, stat.gid, (err: BusinessError) => {
2934    // Do something.
2935  });
2936  ```
2937
2938
2939## fileio.lchownSync<sup>7+</sup>
2940
2941lchownSync(path: string, uid: number, gid: number): void
2942
2943Changes the file owner based on the file path and changes the owner of the symbolic link (not the referenced file). This API returns the result synchronously.
2944
2945> **NOTE**
2946>
2947> This API is deprecated since API version 9.
2948
2949**System capability**: SystemCapability.FileManagement.File.FileIO
2950
2951**Parameters**
2952
2953| Name| Type  | Mandatory| Description                      |
2954| ------ | ------ | ---- | -------------------------- |
2955| path   | string | Yes  | Application sandbox path of the file.|
2956| uid    | number | Yes  | New UID.                 |
2957| gid    | number | Yes  | New GID.                 |
2958
2959**Example**
2960
2961  ```ts
2962  let filePath = pathDir + "/test.txt";
2963  let stat = fileio.statSync(filePath);
2964  fileio.lchownSync(filePath, stat.uid, stat.gid);
2965  ```
2966
2967
2968## fileio.createWatcher<sup>7+</sup>
2969
2970createWatcher(filename: string, events: number, callback: AsyncCallback&lt;number&gt;): Watcher
2971
2972Listens for file or directory changes. This API uses an asynchronous callback to return the result.
2973
2974**System capability**: SystemCapability.FileManagement.File.FileIO
2975
2976**Parameters**
2977
2978| Name  | Type                             | Mandatory| Description                                                        |
2979| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
2980| filePath | string                            | Yes  | Application sandbox path of the file.                                  |
2981| events   | number                            | Yes  | - **1**: The file or directory is renamed.<br>- **2**: The file or directory is modified.<br>- **3**: The file or directory is modified and renamed.|
2982| callback | AsyncCallback&lt;number&gt; | Yes  | Called each time a change is detected.                            |
2983
2984**Return value**
2985
2986  | Type                 | Description        |
2987  | -------------------- | ---------- |
2988| [Watcher](#watcher7) | Promise used to return the **Watcher** instance.|
2989
2990**Example**
2991
2992  ```ts
2993  let filePath = pathDir +"/test.txt";
2994  fileio.createWatcher(filePath, 1, (number: number) => {
2995    console.info("Monitoring times: " + number);
2996  });
2997
2998  ```
2999
3000
3001## Readout
3002
3003Obtains the file read result. This class applies only to the **read()** method.
3004
3005> **NOTE**
3006>
3007> This API is deprecated since API version 9.
3008
3009**System capability**: SystemCapability.FileManagement.File.FileIO
3010
3011| Name       | Type      | Readable  | Writable  | Description               |
3012| --------- | ---------- | ---- | ---- | ----------------- |
3013| bytesRead | number     | Yes   | Yes   | Length of the data read.          |
3014| offset    | number     | Yes   | Yes   | Position of the buffer to which the data will be read in reference to the start address of the buffer.|
3015| buffer    | ArrayBuffer | Yes   | Yes   | Buffer for storing the data read.      |
3016
3017
3018## Stat
3019
3020Provides detailed file information. Before calling a method of the **Stat** class, use the [stat()](#fileiostat) method synchronously or asynchronously to create a **Stat** instance.
3021
3022> **NOTE**
3023>
3024> This API is deprecated since API version 9. Use [fs.Stat](js-apis-file-fs.md#stat) instead.
3025
3026**System capability**: SystemCapability.FileManagement.File.FileIO
3027
3028### Attributes
3029
3030| Name    | Type  | Readable  | Writable  | Description                                      |
3031| ------ | ------ | ---- | ---- | ---------------------------------------- |
3032| dev    | number | Yes   | No   | Major device number.                           |
3033| ino    | number | Yes   | No   | File ID. Different files on the same device have different **ino**s.                |
3034| mode   | number | Yes   | No   | File type and permissions. The first four bits indicate the file type, and the last 12 bits indicate the permissions. The bit fields are described as follows:<br>- **0o170000**: mask used to obtain the file type.<br>- **0o140000**: The file is a socket.<br>- **0o120000**: The file is a symbolic link.<br>- **0o100000**: The file is a regular file.<br>- **0o060000**: The file is a block device.<br>- **0o040000**: The file is a directory.<br>- **0o020000**: The file is a character device.<br>- **0o010000**: The file is a named pipe (FIFO).<br>- **0o0700**: mask used to obtain the owner permissions.<br>- **0o0400**: The owner has the permission to read a regular file or a directory entry.<br>- **0o0200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o0100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o0070**: mask used to obtain the user group permissions.<br>- **0o0040**: The user group has the permission to read a regular file or a directory entry.<br>- **0o0020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o0010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o0007**: mask used to obtain the permissions of other users.<br>- **0o0004**: Other users have the permission to read a regular file or a directory entry.<br>- **0o0002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
3035| nlink  | number | Yes   | No   | Number of hard links in the file.                                |
3036| uid    | number | Yes   | No   | User ID, that is ID of the file owner.                               |
3037| gid    | number | Yes   | No   | Group ID, that is, ID of the user group of the file.                               |
3038| rdev   | number | Yes   | No   | Minor device number.                           |
3039| size   | number | Yes   | No   | File size, in bytes. This parameter is valid only for regular files.                  |
3040| blocks | number | Yes   | No   | Number of blocks occupied by a file. Each block is 512 bytes.                  |
3041| atime  | number | Yes   | No   | Time of the last access to the file. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970.       |
3042| mtime  | number | Yes   | No   | Time of the last modification to the file. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970.       |
3043| ctime  | number | Yes   | No   | Time of the last status change of the file. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970.      |
3044
3045
3046### isBlockDevice
3047
3048isBlockDevice(): boolean
3049
3050Checks whether this file is a block special file. A block special file supports access by block only, and it is cached when accessed.
3051
3052> **NOTE**
3053>
3054> This API is deprecated since API version 9. Use [fs.Stat.isBlockDevice](js-apis-file-fs.md#isblockdevice) instead.
3055
3056**System capability**: SystemCapability.FileManagement.File.FileIO
3057
3058**Return value**
3059
3060  | Type     | Description              |
3061  | ------- | ---------------- |
3062  | boolean | Whether the file is a block special file.|
3063
3064**Example**
3065
3066  ```ts
3067  let filePath = pathDir + "/test.txt";
3068  let isBLockDevice = fileio.statSync(filePath).isBlockDevice();
3069  ```
3070
3071
3072### isCharacterDevice
3073
3074isCharacterDevice(): boolean
3075
3076Checks whether this file is a character special file. A character special file supports random access, and it is not cached when accessed.
3077
3078> **NOTE**
3079>
3080> This API is deprecated since API version 9. Use [fs.Stat.isCharacterDevice](js-apis-file-fs.md#ischaracterdevice) instead.
3081
3082**System capability**: SystemCapability.FileManagement.File.FileIO
3083
3084**Return value**
3085
3086  | Type     | Description               |
3087  | ------- | ----------------- |
3088  | boolean | Whether the file is a character special file.|
3089
3090**Example**
3091
3092  ```ts
3093  let filePath = pathDir + "/test.txt";
3094  let isCharacterDevice = fileio.statSync(filePath).isCharacterDevice();
3095  ```
3096
3097
3098### isDirectory
3099
3100isDirectory(): boolean
3101
3102Checks whether this file is a directory.
3103
3104> **NOTE**
3105>
3106> This API is deprecated since API version 9. Use [fs.Stat.isDirectory](js-apis-file-fs.md#isdirectory) instead.
3107
3108**System capability**: SystemCapability.FileManagement.File.FileIO
3109
3110**Return value**
3111
3112  | Type     | Description           |
3113  | ------- | ------------- |
3114  | boolean | Whether the file is a directory.|
3115
3116**Example**
3117
3118  ```ts
3119  let dirPath = pathDir + "/test";
3120  let isDirectory = fileio.statSync(dirPath).isDirectory();
3121  ```
3122
3123
3124### isFIFO
3125
3126isFIFO(): boolean
3127
3128Checks whether this file is a named pipe (or FIFO). Named pipes are used for inter-process communication.
3129
3130> **NOTE**
3131>
3132> This API is deprecated since API version 9. Use [fs.Stat.isFIFO](js-apis-file-fs.md#isfifo) instead.
3133
3134**System capability**: SystemCapability.FileManagement.File.FileIO
3135
3136**Return value**
3137
3138  | Type     | Description                   |
3139  | ------- | --------------------- |
3140  | boolean | Whether the file is an FIFO.|
3141
3142**Example**
3143
3144  ```ts
3145  let filePath = pathDir + "/test.txt";
3146  let isFIFO = fileio.statSync(filePath).isFIFO();
3147  ```
3148
3149
3150### isFile
3151
3152isFile(): boolean
3153
3154Checks whether this file is a regular file.
3155
3156> **NOTE**
3157>
3158> This API is deprecated since API version 9. Use [fs.Stat.isFile](js-apis-file-fs.md#isfile) instead.
3159
3160**System capability**: SystemCapability.FileManagement.File.FileIO
3161
3162**Return value**
3163
3164  | Type     | Description             |
3165  | ------- | --------------- |
3166  | boolean | Whether the file is a regular file.|
3167
3168**Example**
3169
3170  ```ts
3171  let filePath = pathDir + "/test.txt";
3172  let isFile = fileio.statSync(filePath).isFile();
3173  ```
3174
3175
3176### isSocket
3177
3178isSocket(): boolean
3179
3180Checks whether this file is a socket.
3181
3182> **NOTE**
3183>
3184> This API is deprecated since API version 9. Use [fs.Stat.isSocket](js-apis-file-fs.md#issocket) instead.
3185
3186**System capability**: SystemCapability.FileManagement.File.FileIO
3187
3188**Return value**
3189
3190  | Type     | Description            |
3191  | ------- | -------------- |
3192  | boolean | Whether the file is a socket.|
3193
3194**Example**
3195
3196  ```ts
3197  let filePath = pathDir + "/test.txt";
3198  let isSocket = fileio.statSync(filePath).isSocket();
3199  ```
3200
3201
3202### isSymbolicLink
3203
3204isSymbolicLink(): boolean
3205
3206Checks whether this file is a symbolic link.
3207
3208> **NOTE**
3209>
3210> This API is deprecated since API version 9. Use [fs.Stat.isSymbolicLink](js-apis-file-fs.md#issymboliclink) instead.
3211
3212**System capability**: SystemCapability.FileManagement.File.FileIO
3213
3214**Return value**
3215
3216  | Type     | Description             |
3217  | ------- | --------------- |
3218  | boolean | Whether the file is a symbolic link.|
3219
3220**Example**
3221
3222  ```ts
3223  let filePath = pathDir + "/test";
3224  let isSymbolicLink = fileio.statSync(filePath).isSymbolicLink();
3225  ```
3226
3227
3228## Watcher<sup>7+</sup>
3229
3230Listens for the changes of a file. You can call the **Watcher.stop()** method synchronously or asynchronously to stop the listening.
3231
3232
3233### stop<sup>7+</sup>
3234
3235stop(): Promise&lt;void&gt;
3236
3237Stops the **watcher** instance. This API uses a promise to return the result.
3238
3239**System capability**: SystemCapability.FileManagement.File.FileIO
3240
3241**Example**
3242
3243  ```ts
3244  let filePath = path + "/test.txt";
3245  let watcher = fileio.createWatcher(filePath, 1, (number: number) => {
3246    console.info("Monitoring times: " + number);
3247  });
3248  watcher.stop().then(() => {
3249    console.info("Watcher stopped");
3250  });
3251  ```
3252
3253
3254### stop<sup>7+</sup>
3255
3256stop(callback: AsyncCallback&lt;void&gt;): void
3257
3258Stops the **watcher** instance. This API uses an asynchronous callback to return the result.
3259
3260**System capability**: SystemCapability.FileManagement.File.FileIO
3261
3262**Parameters**
3263
3264  | Name     | Type                       | Mandatory  | Description                    |
3265  | -------- | ------------------------- | ---- | ---------------------- |
3266  | callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when **watcher** is stopped asynchronously.|
3267
3268**Example**
3269
3270  ```ts
3271  let filePath = path +"/test.txt";
3272  let watcher = fileio.createWatcher(filePath, 1, (number: number) => {
3273    console.info("Monitoring times: " + number);
3274  });
3275  watcher.stop(() => {
3276    console.info("Watcher stopped");
3277  })
3278  ```
3279
3280
3281## Stream
3282
3283Provides a stream for file operations. Before calling any API of the **Stream** class, use **createStream()** to create a **Stream** instance synchronously or asynchronously.
3284
3285> **NOTE**
3286>
3287> This API is deprecated since API version 9. Use [fs.Stream](js-apis-file-fs.md#stream) instead.
3288
3289### close<sup>7+</sup>
3290
3291close(): Promise&lt;void&gt;
3292
3293Closes the stream. This API uses a promise to return the result.
3294
3295> **NOTE**
3296>
3297> This API is deprecated since API version 9. Use [fs.Stream.close](js-apis-file-fs.md#close) instead.
3298
3299**System capability**: SystemCapability.FileManagement.File.FileIO
3300
3301**Return value**
3302
3303  | Type                 | Description           |
3304  | ------------------- | ------------- |
3305  | Promise&lt;void&gt; | Promise used to return the result.|
3306
3307**Example**
3308
3309  ```ts
3310  import { BusinessError } from '@ohos.base';
3311  let filePath = pathDir + "/test.txt";
3312  let ss = fileio.createStreamSync(filePath, "r+");
3313  ss.close().then(() => {
3314    console.info("File stream closed");
3315  }).catch((err: BusinessError) => {
3316    console.info("close fileStream  failed with error:" + err);
3317  });
3318  ```
3319
3320
3321### close<sup>7+</sup>
3322
3323close(callback: AsyncCallback&lt;void&gt;): void
3324
3325Closes the stream. This API uses an asynchronous callback to return the result.
3326
3327> **NOTE**
3328>
3329> This API is deprecated since API version 9. Use [fs.Stream.close](js-apis-file-fs.md#close-1) instead.
3330
3331**System capability**: SystemCapability.FileManagement.File.FileIO
3332
3333**Parameters**
3334
3335  | Name     | Type                       | Mandatory  | Description           |
3336  | -------- | ------------------------- | ---- | ------------- |
3337  | callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked immediately after the stream is closed.|
3338
3339**Example**
3340
3341  ```ts
3342  import { BusinessError } from '@ohos.base';
3343  let filePath = pathDir + "/test.txt";
3344  let ss = fileio.createStreamSync(filePath, "r+");
3345  ss.close((err: BusinessError) => {
3346    // Do something.
3347  });
3348  ```
3349
3350
3351### closeSync
3352
3353closeSync(): void
3354
3355Closes the stream. This API returns the result synchronously.
3356
3357> **NOTE**
3358>
3359> This API is deprecated since API version 9. Use [fs.Stream.closeSync](js-apis-file-fs.md#closesync) instead.
3360
3361**System capability**: SystemCapability.FileManagement.File.FileIO
3362
3363**Example**
3364
3365  ```ts
3366  let filePath = pathDir + "/test.txt";
3367  let ss = fileio.createStreamSync(filePath, "r+");
3368  ss.closeSync();
3369  ```
3370
3371
3372### flush<sup>7+</sup>
3373
3374flush(): Promise&lt;void&gt;
3375
3376Flushes the stream. This API uses a promise to return the result.
3377
3378> **NOTE**
3379>
3380> This API is deprecated since API version 9. Use [fs.Stream.flush](js-apis-file-fs.md#flush) instead.
3381
3382**System capability**: SystemCapability.FileManagement.File.FileIO
3383
3384**Return value**
3385
3386  | Type                 | Description           |
3387  | ------------------- | ------------- |
3388  | Promise&lt;void&gt; | Promise used to return the result.|
3389
3390**Example**
3391
3392  ```ts
3393  import { BusinessError } from '@ohos.base';
3394  let filePath = pathDir + "/test.txt";
3395  let ss = fileio.createStreamSync(filePath, "r+");
3396  ss.flush().then(() => {
3397    console.info("Stream flushed");
3398  }).catch((err: BusinessError) => {
3399    console.info("flush failed with error:" + err);
3400  });
3401  ```
3402
3403
3404### flush<sup>7+</sup>
3405
3406flush(callback: AsyncCallback&lt;void&gt;): void
3407
3408Flushes the stream. This API uses an asynchronous callback to return the result.
3409
3410> **NOTE**
3411>
3412> This API is deprecated since API version 9. Use [fs.Stream.flush](js-apis-file-fs.md#flush-1) instead.
3413
3414**System capability**: SystemCapability.FileManagement.File.FileIO
3415
3416**Parameters**
3417
3418  | Name     | Type                       | Mandatory  | Description            |
3419  | -------- | ------------------------- | ---- | -------------- |
3420  | callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the stream is asynchronously flushed.|
3421
3422**Example**
3423
3424  ```ts
3425  import { BusinessError } from '@ohos.base';
3426  let filePath = pathDir + "/test.txt";
3427  let ss = fileio.createStreamSync(filePath, "r+");
3428  ss.flush((err: BusinessError) => {
3429    // Do something.
3430  });
3431  ```
3432
3433
3434### flushSync<sup>7+</sup>
3435
3436flushSync(): void
3437
3438Flushes the stream. This API returns the result synchronously.
3439
3440> **NOTE**
3441>
3442> This API is deprecated since API version 9. Use [fs.Stream.flushSync](js-apis-file-fs.md#flushsync) instead.
3443
3444**System capability**: SystemCapability.FileManagement.File.FileIO
3445
3446**Example**
3447
3448  ```ts
3449  let filePath = pathDir + "/test.txt";
3450  let ss = fileio.createStreamSync(filePath, "r+");
3451  ss.flushSync();
3452  ```
3453
3454
3455### write<sup>7+</sup>
3456
3457write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): Promise&lt;number&gt;
3458
3459Writes data into the stream. This API uses a promise to return the result.
3460
3461> **NOTE**
3462>
3463> This API is deprecated since API version 9. Use [fs.Stream.write](js-apis-file-fs.md#write) instead.
3464
3465**System capability**: SystemCapability.FileManagement.File.FileIO
3466
3467**Parameters**
3468
3469  | Name    | Type                             | Mandatory  | Description                                      |
3470  | ------- | ------------------------------- | ---- | ---------------------------------------- |
3471  | buffer  | ArrayBuffer\|string | Yes   | Data to write. It can be a string or data from a buffer.                    |
3472  | options | Object                          | No   | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size |
3473
3474**Return value**
3475
3476  | Type                   | Description      |
3477  | --------------------- | -------- |
3478  | Promise&lt;number&gt; | Promise used to return the length of the data written.|
3479
3480**Example**
3481
3482  ```ts
3483  import { BusinessError } from '@ohos.base';
3484  let filePath = pathDir + "/test.txt";
3485  let ss = fileio.createStreamSync(filePath, "r+");
3486  class Option {
3487    offset: number = 0;
3488    length: number = 4096;
3489    position: number = 0;
3490    encoding: string = 'utf-8';
3491  }
3492  let option = new Option();
3493  option.offset = 1;
3494  option.length = 5;
3495  option.position = 5;
3496  ss.write("hello, world", option).then((number: number) => {
3497    console.info("write succeed and size is:" + number);
3498  }).catch((err: BusinessError) => {
3499    console.info("write failed with error:" + err);
3500  });
3501  ```
3502
3503
3504### write<sup>7+</sup>
3505
3506write(buffer: ArrayBuffer|string, options: { offset?: number; length?: number; position?: number; encoding?: string; }, callback: AsyncCallback&lt;number&gt;): void
3507
3508Writes data into the stream. This API uses an asynchronous callback to return the result.
3509
3510> **NOTE**
3511>
3512> This API is deprecated since API version 9. Use [fs.Stream.write](js-apis-file-fs.md#write-1) instead.
3513
3514**System capability**: SystemCapability.FileManagement.File.FileIO
3515
3516**Parameters**
3517
3518  | Name  | Type                           | Mandatory| Description                                                        |
3519  | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
3520  | buffer   | ArrayBuffer\|string | Yes  | Data to write. It can be a string or data from a buffer.                    |
3521  | options  | Object                          | No  | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
3522  | callback | AsyncCallback&lt;number&gt;     | Yes  | Callback invoked when the data is written asynchronously.                              |
3523
3524**Example**
3525
3526  ```ts
3527  import { BusinessError } from '@ohos.base';
3528  let filePath = pathDir + "/test.txt";
3529  let ss = fileio.createStreamSync(filePath, "r+");
3530  class Option {
3531    offset: number = 0;
3532    length: number = 4096;
3533    position: number = 0;
3534    encoding: string = 'utf-8';
3535  }
3536  let option = new Option();
3537  option.offset = 1;
3538  option.length = 5;
3539  option.position = 5;
3540  ss.write("hello, world", option, (err: BusinessError, bytesWritten: number) => {
3541    if (bytesWritten) {
3542      // Do something.
3543      console.info("write succeed and size is:" + bytesWritten);
3544    }
3545  });
3546  ```
3547
3548
3549### writeSync<sup>7+</sup>
3550
3551writeSync(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; position?: number; encoding?: string; }): number
3552
3553Writes data into the stream. This API returns the result synchronously.
3554
3555> **NOTE**
3556>
3557> This API is deprecated since API version 9. Use [fs.Stream.writeSync](js-apis-file-fs.md#writesync) instead.
3558
3559**System capability**: SystemCapability.FileManagement.File.FileIO
3560
3561**Parameters**
3562
3563  | Name    | Type                             | Mandatory  | Description                                      |
3564  | ------- | ------------------------------- | ---- | ---------------------------------------- |
3565  | buffer  | ArrayBuffer\|string | Yes   | Data to write. It can be a string or data from a buffer.                    |
3566  | options | Object                          | No   | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size |
3567
3568**Return value**
3569
3570  | Type    | Description      |
3571  | ------ | -------- |
3572  | number | Length of the data written in the file.|
3573
3574**Example**
3575
3576  ```ts
3577  let filePath = pathDir + "/test.txt";
3578  let ss = fileio.createStreamSync(filePath,"r+");
3579  class Option {
3580    offset: number = 0;
3581    length: number = 4096;
3582    position: number = 0;
3583    encoding: string = 'utf-8';
3584  }
3585  let option = new Option();
3586  option.offset = 1;
3587  option.length = 5;
3588  option.position = 5;
3589  let num = ss.writeSync("hello, world", option);
3590  ```
3591
3592
3593### read<sup>7+</sup>
3594
3595read(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length?: number; }): Promise&lt;ReadOut&gt;
3596
3597Reads data from the stream. This API uses a promise to return the result.
3598
3599> **NOTE**
3600>
3601> This API is deprecated since API version 9. Use [fs.Stream.read](js-apis-file-fs.md#read) instead.
3602
3603**System capability**: SystemCapability.FileManagement.File.FileIO
3604
3605**Parameters**
3606
3607  | Name    | Type         | Mandatory  | Description                                      |
3608  | ------- | ----------- | ---- | ---------------------------------------- |
3609  | buffer  | ArrayBuffer | Yes   | Buffer used to store the file read.                             |
3610  | options | Object      | No   | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
3611
3612**Return value**
3613
3614  | Type                                | Description    |
3615  | ---------------------------------- | ------ |
3616  | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
3617
3618**Example**
3619
3620  ```ts
3621  import { BusinessError } from '@ohos.base';
3622  import buffer from '@ohos.buffer';
3623  let filePath = pathDir + "/test.txt";
3624  let ss = fileio.createStreamSync(filePath, "r+");
3625  let arrayBuffer = new ArrayBuffer(4096);
3626  class Option {
3627    offset: number = 0;
3628    length: number = 4096;
3629    position: number = 0;
3630  }
3631  let option = new Option();
3632  option.offset = 1;
3633  option.length = 5;
3634  option.position = 5;
3635  ss.read(arrayBuffer, option).then((readLen: number) => {
3636    console.info("Read data successfully");
3637    let buf = buffer.from(arrayBuffer, 0, readLen);
3638    console.info(`The content of file: ${buf.toString()}`);
3639  }).catch((err: BusinessError) => {
3640    console.info("read data failed with error:" + err);
3641  });
3642  ```
3643
3644
3645### read<sup>7+</sup>
3646
3647read(buffer: ArrayBuffer, options: { position?: number; offset?: number; length?: number; }, callback: AsyncCallback&lt;ReadOut&gt;): void
3648
3649Reads data from the stream. This API uses an asynchronous callback to return the result.
3650
3651> **NOTE**
3652>
3653> This API is deprecated since API version 9. Use [fs.Stream.read](js-apis-file-fs.md#read-1) instead.
3654
3655**System capability**: SystemCapability.FileManagement.File.FileIO
3656
3657**Parameters**
3658
3659  | Name     | Type                                      | Mandatory  | Description                                      |
3660  | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3661  | buffer   | ArrayBuffer                              | Yes   | Buffer used to store the file read.                             |
3662  | options  | Object                                   | No   | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
3663  | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes   | Callback invoked when data is read asynchronously from the stream.                        |
3664
3665**Example**
3666
3667  ```ts
3668  import { BusinessError } from '@ohos.base';
3669  import buffer from '@ohos.buffer';
3670  let filePath = pathDir + "/test.txt";
3671  let ss = fileio.createStreamSync(filePath, "r+");
3672  let arrayBuffer = new ArrayBuffer(4096);
3673  class Option {
3674    offset: number = 0;
3675    length: number = 4096;
3676    position: number = 0;
3677  }
3678  let option = new Option();
3679  option.offset = 1;
3680  option.length = 5;
3681  option.position = 5;
3682  ss.read(arrayBuffer, option, (err: BusinessError, readLen: number) => {
3683    if (readLen) {
3684      console.info("Read data successfully");
3685      let buf = buffer.from(arrayBuffer, 0, readLen);
3686      console.info(`The content of file: ${buf.toString()}`);
3687    }
3688  });
3689  ```
3690
3691
3692### readSync<sup>7+</sup>
3693
3694readSync(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length?: number; }): number
3695
3696Reads data from the stream. This API returns the result synchronously.
3697
3698> **NOTE**
3699>
3700> This API is deprecated since API version 9. Use [fs.Stream.readSync](js-apis-file-fs.md#readsync) instead.
3701
3702**System capability**: SystemCapability.FileManagement.File.FileIO
3703
3704**Parameters**
3705
3706  | Name    | Type         | Mandatory  | Description                                      |
3707  | ------- | ----------- | ---- | ---------------------------------------- |
3708  | buffer  | ArrayBuffer | Yes   | Buffer used to store the file read.                             |
3709  | options | Object      | No   | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. This parameter is optional. The default value is **0**.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
3710
3711**Return value**
3712
3713  | Type    | Description      |
3714  | ------ | -------- |
3715  | number | Length of the data read.|
3716
3717**Example**
3718
3719  ```ts
3720  let filePath = pathDir + "/test.txt";
3721  let ss = fileio.createStreamSync(filePath, "r+");
3722  class Option {
3723    offset: number = 0;
3724    length: number = 4096;
3725    position: number = 0;
3726  }
3727  let option = new Option();
3728  option.offset = 1;
3729  option.length = 5;
3730  option.position = 5;
3731  let buf = new ArrayBuffer(4096)
3732  let num = ss.readSync(buf, option);
3733  ```
3734
3735
3736## Dir
3737
3738Manages directories. Before calling a method of the **Dir** class, use the **opendir()** method synchronously or asynchronously to create a **Dir** instance.
3739
3740> **NOTE**
3741>
3742> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead.
3743
3744### read
3745
3746read(): Promise&lt;Dirent&gt;
3747
3748Reads the next directory entry. This API uses a promise to return the result.
3749
3750> **NOTE**
3751>
3752> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead.
3753
3754**System capability**: SystemCapability.FileManagement.File.FileIO
3755
3756**Return value**
3757
3758  | Type                              | Description           |
3759  | -------------------------------- | ------------- |
3760| Promise&lt;[Dirent](#dirent)&gt; | Promise used to return the directory entry read.|
3761
3762**Example**
3763
3764  ```ts
3765  import { BusinessError } from '@ohos.base';
3766  dir.read().then((dirent: fileio.Dirent) => {
3767    console.log("read succeed, the name of dirent is " + dirent.name);
3768  }).catch((err: BusinessError) => {
3769    console.info("read failed with error:" + err);
3770  });
3771  ```
3772
3773
3774### read
3775
3776read(callback: AsyncCallback&lt;Dirent&gt;): void
3777
3778Reads the next directory entry. This API uses an asynchronous callback to return the result.
3779
3780> **NOTE**
3781>
3782> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile-1) instead.
3783
3784**System capability**: SystemCapability.FileManagement.File.FileIO
3785
3786**Parameters**
3787
3788  | Name     | Type                                    | Mandatory  | Description              |
3789  | -------- | -------------------------------------- | ---- | ---------------- |
3790  | callback | AsyncCallback&lt;[Dirent](#dirent)&gt; | Yes   | Callback invoked when the next directory entry is asynchronously read.|
3791
3792**Example**
3793
3794  ```ts
3795  import { BusinessError } from '@ohos.base';
3796  dir.read((err: BusinessError, dirent: fileio.Dirent) {
3797    if (dirent) {
3798      // Do something.
3799      console.log("read succeed, the name of file is " + dirent.name);
3800    }
3801  });
3802  ```
3803
3804
3805### readSync
3806
3807readSync(): Dirent
3808
3809Reads the next directory entry. This API returns the result synchronously.
3810
3811> **NOTE**
3812>
3813> This API is deprecated since API version 9. Use [fs.listFileSync](js-apis-file-fs.md#fslistfilesync) instead.
3814
3815**System capability**: SystemCapability.FileManagement.File.FileIO
3816
3817**Return value**
3818
3819  | Type               | Description      |
3820  | ----------------- | -------- |
3821  | [Dirent](#dirent) | Directory entry read.|
3822
3823**Example**
3824
3825  ```ts
3826  let dirent = dir.readSync();
3827  ```
3828
3829
3830### close<sup>7+</sup>
3831
3832close(): Promise&lt;void&gt;
3833
3834Closes a directory. This API uses a promise to return the result. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir.
3835
3836> **NOTE**
3837>
3838> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead.
3839
3840**System capability**: SystemCapability.FileManagement.File.FileIO
3841
3842**Example**
3843
3844  ```ts
3845  import { BusinessError } from '@ohos.base';
3846  dir.close().then((err: BusinessError) => {
3847    console.info("close dir successfully");
3848  });
3849  ```
3850
3851
3852### close<sup>7+</sup>
3853
3854close(callback: AsyncCallback&lt;void&gt;): void
3855
3856Closes a directory. This API uses an asynchronous callback to return the result. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir.
3857
3858> **NOTE**
3859>
3860> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile-1) instead.
3861
3862**System capability**: SystemCapability.FileManagement.File.FileIO
3863
3864**Example**
3865
3866  ```ts
3867  import { BusinessError } from '@ohos.base';
3868  dir.close((err: BusinessError) => {
3869    console.info("close dir successfully");
3870  });
3871  ```
3872
3873
3874### closeSync
3875
3876closeSync(): void
3877
3878Closes a directory. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir.
3879
3880> **NOTE**
3881>
3882> This API is deprecated since API version 9. Use [fs.listFileSync](js-apis-file-fs.md#fslistfilesync) instead.
3883
3884**System capability**: SystemCapability.FileManagement.File.FileIO
3885
3886**Example**
3887
3888  ```ts
3889  dir.closeSync();
3890  ```
3891
3892
3893## Dirent
3894
3895Provides information about files and directories. Before calling a method of the **Dirent** class, use the [dir.read()](#read) method synchronously or asynchronously to create a **Dirent** instance.
3896
3897> **NOTE**
3898>
3899> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead.
3900
3901**System capability**: SystemCapability.FileManagement.File.FileIO
3902
3903### Attributes
3904
3905| Name  | Type  | Readable  | Writable  | Description     |
3906| ---- | ------ | ---- | ---- | ------- |
3907| name | string | Yes   | No   | Directory entry name.|
3908
3909
3910### isBlockDevice
3911
3912isBlockDevice(): boolean
3913
3914Checks whether this directory entry is a block special file. A block special file supports access by block only, and it is cached when accessed.
3915
3916> **NOTE**
3917>
3918> This API is deprecated since API version 9.
3919
3920**System capability**: SystemCapability.FileManagement.File.FileIO
3921
3922**Return value**
3923
3924  | Type     | Description              |
3925  | ------- | ---------------- |
3926  | boolean | Whether the directory entry is a block special file.|
3927
3928**Example**
3929
3930  ```ts
3931  let dir = fileio.opendirSync(pathDir);
3932  let isBLockDevice = dir.readSync().isBlockDevice();
3933  ```
3934
3935
3936### isCharacterDevice
3937
3938isCharacterDevice(): boolean
3939
3940Checks whether a directory entry is a character special file. A character special file supports random access, and it is not cached when accessed.
3941
3942> **NOTE**
3943>
3944> This API is deprecated since API version 9.
3945
3946**System capability**: SystemCapability.FileManagement.File.FileIO
3947
3948**Return value**
3949
3950  | Type     | Description               |
3951  | ------- | ----------------- |
3952  | boolean | Whether the directory entry is a character special file.|
3953
3954**Example**
3955
3956  ```ts
3957  let dir = fileio.opendirSync(pathDir);
3958  let isCharacterDevice = dir.readSync().isCharacterDevice();
3959  ```
3960
3961
3962### isDirectory
3963
3964isDirectory(): boolean
3965
3966Checks whether a directory entry is a directory.
3967
3968> **NOTE**
3969>
3970> This API is deprecated since API version 9.
3971
3972**System capability**: SystemCapability.FileManagement.File.FileIO
3973
3974**Return value**
3975
3976  | Type     | Description           |
3977  | ------- | ------------- |
3978  | boolean | Whether the directory entry is a directory.|
3979
3980**Example**
3981
3982  ```ts
3983  let dir = fileio.opendirSync(pathDir);
3984  let isDirectory = dir.readSync().isDirectory();
3985  ```
3986
3987
3988### isFIFO
3989
3990isFIFO(): boolean
3991
3992Checks whether this directory entry is a named pipe (or FIFO). Named pipes are used for inter-process communication.
3993
3994> **NOTE**
3995>
3996> This API is deprecated since API version 9.
3997
3998**System capability**: SystemCapability.FileManagement.File.FileIO
3999
4000**Return value**
4001
4002  | Type     | Description             |
4003  | ------- | --------------- |
4004  | boolean | Whether the directory entry is a FIFO.|
4005
4006**Example**
4007
4008  ```ts
4009  let dir = fileio.opendirSync(pathDir);
4010  let isFIFO = dir.readSync().isFIFO();
4011  ```
4012
4013
4014### isFile
4015
4016isFile(): boolean
4017
4018Checks whether a directory entry is a regular file.
4019
4020> **NOTE**
4021>
4022> This API is deprecated since API version 9.
4023
4024**System capability**: SystemCapability.FileManagement.File.FileIO
4025
4026**Return value**
4027
4028  | Type     | Description             |
4029  | ------- | --------------- |
4030  | boolean | Whether the directory entry is a regular file.|
4031
4032**Example**
4033
4034  ```ts
4035  let dir = fileio.opendirSync(pathDir);
4036  let isFile = dir.readSync().isFile();
4037  ```
4038
4039
4040### isSocket
4041
4042isSocket(): boolean
4043
4044Checks whether a directory entry is a socket.
4045
4046> **NOTE**
4047>
4048> This API is deprecated since API version 9.
4049
4050**System capability**: SystemCapability.FileManagement.File.FileIO
4051
4052**Return value**
4053
4054  | Type     | Description            |
4055  | ------- | -------------- |
4056  | boolean | Whether the directory entry is a socket.|
4057
4058**Example**
4059
4060  ```ts
4061  let dir = fileio.opendirSync(pathDir);
4062  let isSocket = dir.readSync().isSocket();
4063  ```
4064
4065
4066### isSymbolicLink
4067
4068isSymbolicLink(): boolean
4069
4070Checks whether a directory entry is a symbolic link.
4071
4072> **NOTE**
4073>
4074> This API is deprecated since API version 9.
4075
4076**System capability**: SystemCapability.FileManagement.File.FileIO
4077
4078**Return value**
4079
4080  | Type     | Description             |
4081  | ------- | --------------- |
4082  | boolean | Whether the directory entry is a symbolic link.|
4083
4084**Example**
4085
4086  ```ts
4087  let dir = fileio.opendirSync(pathDir);
4088  let isSymbolicLink = dir.readSync().isSymbolicLink();
4089  ```
4090