The **fs** module provides APIs for file operations, including basic file management, directory management, file information statistics, and data read and write using a stream.
The **fs** module provides APIs for file operations, including basic file management, directory management, file information statistics, and data read and write using a stream.
> **NOTE**<br>
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
## Modules to Import
...
@@ -11,10 +12,6 @@ The **fs** module provides APIs for file operations, including basic file manage
...
@@ -11,10 +12,6 @@ The **fs** module provides APIs for file operations, including basic file manage
importfsfrom'@ohos.file.fs';
importfsfrom'@ohos.file.fs';
```
```
## Error Code Description
The APIs of this module supports processing of error codes. For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Guidelines
## Guidelines
Before using the APIs provided by this module to perform operations on a file or folder, obtain the application sandbox path of the file or folder as follows:
Before using the APIs provided by this module to perform operations on a file or folder, obtain the application sandbox path of the file or folder as follows:
...
@@ -61,9 +58,13 @@ Obtains detailed file information. This API uses a promise to return the result.
...
@@ -61,9 +58,13 @@ Obtains detailed file information. This API uses a promise to return the result.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ---------------------------- | ---------- |
| ---------------------------- | ---------- |
| Promise<[Stat](#stat)> | Promise used to return the file information obtained.|
| Promise<[Stat](#stat)> | Promise used to return the file information obtained.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -91,6 +92,10 @@ Obtains detailed file information. This API uses an asynchronous callback to ret
...
@@ -91,6 +92,10 @@ Obtains detailed file information. This API uses an asynchronous callback to ret
| file | string\|number | Yes | Application sandbox path or FD of the file. |
| file | string\|number | Yes | Application sandbox path or FD of the file. |
| callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked to return the file information obtained.|
| callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked to return the file information obtained.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
```js
```js
...
@@ -117,12 +122,15 @@ Obtains detailed file information synchronously.
...
@@ -117,12 +122,15 @@ Obtains detailed file information synchronously.
| path | string | Yes | Application sandbox path of the file. |
| path | string | Yes | Application sandbox path of the file. |
| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. |
| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the file exists; the value **false** means the opposite.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -211,9 +226,13 @@ Synchronously checks whether a file exists.
...
@@ -211,9 +226,13 @@ Synchronously checks whether a file exists.
| src | string\|number | Yes | Path or FD of the file to copy. |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file of the same name.|
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file of the same name.|
| src | string\|number | Yes | Path or FD of the file to copy. |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. 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.|
| mode | number | No | Whether to overwrite the file of the same name in the destination path. 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.|
| callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. |
| callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -390,11 +429,15 @@ Synchronously copies a file.
...
@@ -390,11 +429,15 @@ Synchronously copies a file.
| src | string\|number | Yes | Path or FD of the file to copy. |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. 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.|
| mode | number | No | Whether to overwrite the file of the same name in the destination path. 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.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -404,7 +447,6 @@ Synchronously copies a file.
...
@@ -404,7 +447,6 @@ Synchronously copies a file.
fs.copyFileSync(srcPath,dstPath);
fs.copyFileSync(srcPath,dstPath);
```
```
## fs.mkdir
## fs.mkdir
mkdir(path: string): Promise<void>
mkdir(path: string): Promise<void>
...
@@ -421,9 +463,13 @@ Creates a directory. This API uses a promise to return the result.
...
@@ -421,9 +463,13 @@ Creates a directory. This API uses a promise to return the result.
@@ -505,9 +556,13 @@ Opens a file. This API uses a promise to return the result. File uniform resourc
...
@@ -505,9 +556,13 @@ Opens a file. This API uses a promise to return the result. File uniform resourc
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| --------------------- | ----------- |
| --------------------- | ----------- |
| Promise<[File](#file)> | Promise used to return the file object.|
| Promise<[File](#file)> | Promise used to return the file object.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -536,6 +591,10 @@ Opens a file. This API uses an asynchronous callback to return the result. File
...
@@ -536,6 +591,10 @@ Opens a file. This API uses an asynchronous callback to return the result. File
| path | string | Yes | Application sandbox path or URI of the file. |
| path | string | Yes | Application sandbox path or URI of the file. |
| mode | number | No | [Mode](#openmode) for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **OpenMode.READ_ONLY(0o0)**: Open the file in read-only mode.<br>- **OpenMode.WRITE_ONLY(0o1)**: Open the file in write-only mode.<br>- **OpenMode.READ_WRITE(0o2)**: Open the file in read/write mode.<br>You can also specify the following options, separated by a bitwise OR operator (|). By default, no additional options are given.<br>- **OpenMode.CREATE(0o100)**: If the file does not exist, create it.<br>- **OpenMode.TRUNC(0o1000)**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **OpenMode.APPEND(0o2000)**: Open the file in append mode. New data will be added to the end of the file.<br>- **OpenMode.NONBLOCK(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>- **OpenMode.DIR(0o200000)**: If **path** does not point to a directory, throw an exception.<br>- **OpenMode.NOFOLLOW(0o400000)**: If **path** points to a symbolic link, throw an exception.<br>- **OpenMode.SYNC(0o4010000)**: Open the file in synchronous I/O mode.|
| mode | number | No | [Mode](#openmode) for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **OpenMode.READ_ONLY(0o0)**: Open the file in read-only mode.<br>- **OpenMode.WRITE_ONLY(0o1)**: Open the file in write-only mode.<br>- **OpenMode.READ_WRITE(0o2)**: Open the file in read/write mode.<br>You can also specify the following options, separated by a bitwise OR operator (|). By default, no additional options are given.<br>- **OpenMode.CREATE(0o100)**: If the file does not exist, create it.<br>- **OpenMode.TRUNC(0o1000)**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **OpenMode.APPEND(0o2000)**: Open the file in append mode. New data will be added to the end of the file.<br>- **OpenMode.NONBLOCK(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>- **OpenMode.DIR(0o200000)**: If **path** does not point to a directory, throw an exception.<br>- **OpenMode.NOFOLLOW(0o400000)**: If **path** points to a symbolic link, throw an exception.<br>- **OpenMode.SYNC(0o4010000)**: Open the file in synchronous I/O mode.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
```js
```js
...
@@ -566,9 +625,13 @@ Synchronously opens a file. File URIs are supported.
...
@@ -566,9 +625,13 @@ Synchronously opens a file. File URIs are supported.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | ----------- |
| ------ | ----------- |
| [File](#file) | File object opened.|
| [File](#file) | File object opened.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -597,9 +660,13 @@ Reads data from a file. This API uses a promise to return the result.
...
@@ -597,9 +660,13 @@ Reads data from a file. This API uses a promise to return the result.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ---------------------------------- | ------ |
| ---------------------------------- | ------ |
| Promise<number> | Promise used to return the data read.|
| Promise<number> | Promise used to return the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -626,12 +693,16 @@ Reads data from a file. This API uses an asynchronous callback to return the res
...
@@ -626,12 +693,16 @@ Reads data from a file. This API uses an asynchronous callback to return the res
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (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. This parameter is optional. The default value is the buffer length.|
| options | Object | No | The options are as follows:<br>- **offset** (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. This parameter is optional. The default value is the buffer length.|
| callback | AsyncCallback<number> | Yes | Callback invoked when the data is read asynchronously. |
| callback | AsyncCallback<number> | Yes | Callback invoked when the data is read asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -650,7 +721,6 @@ Reads data from a file. This API uses an asynchronous callback to return the res
...
@@ -650,7 +721,6 @@ Reads data from a file. This API uses an asynchronous callback to return the res
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (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. This parameter is optional. The default value is the buffer length.|
| options | Object | No | The options are as follows:<br>- **offset** (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. This parameter is optional. The default value is the buffer length.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | -------- |
| ------ | -------- |
| number | Length of the data read.|
| number | Length of the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -683,7 +757,6 @@ Synchronously reads data from a file.
...
@@ -683,7 +757,6 @@ Synchronously reads data from a file.
fs.closeSync(file);
fs.closeSync(file);
```
```
## fs.rmdir
## fs.rmdir
rmdir(path: string): Promise<void>
rmdir(path: string): Promise<void>
...
@@ -700,9 +773,13 @@ Deletes a directory. This API uses a promise to return the result.
...
@@ -700,9 +773,13 @@ Deletes a directory. This API uses a promise to return the result.
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<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.|
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<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.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| --------------------- | -------- |
| --------------------- | -------- |
| Promise<number> | Promise used to return the length of the data written.|
| Promise<number> | Promise used to return the length of the data written.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -885,7 +981,6 @@ Writes data into a file. This API uses a promise to return the result.
...
@@ -885,7 +981,6 @@ Writes data into a file. This API uses a promise to return the result.
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<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.|
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<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.|
| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -918,7 +1017,6 @@ Writes data into a file. This API uses an asynchronous callback to return the re
...
@@ -918,7 +1017,6 @@ Writes data into a file. This API uses an asynchronous callback to return the re
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<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.|
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<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.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | -------- |
| ------ | -------- |
| number | Length of the data written in the file.|
| number | Length of the data written in the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -968,9 +1070,13 @@ Truncates a file. This API uses a promise to return the result.
...
@@ -968,9 +1070,13 @@ Truncates a file. This API uses a promise to return the result.
@@ -1089,6 +1203,10 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
...
@@ -1089,6 +1203,10 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
| options | Object | No | The options are as follows:<br>- **offset** (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. This parameter is optional. The default value is the file length.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.|
| options | Object | No | The options are as follows:<br>- **offset** (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. This parameter is optional. The default value is the file length.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback<string> | Yes | Callback invoked to return the content read. |
| callback | AsyncCallback<string> | Yes | Callback invoked to return the content read. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
```js
```js
...
@@ -1102,7 +1220,6 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
...
@@ -1102,7 +1220,6 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| --------------------- | ---------- |
| --------------------- | ---------- |
| Promise<string[]> | Promise used to return the files names listed.|
| Promise<string[]> | Promise used to return the files names listed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -1634,19 +1813,23 @@ Lists all files in a directory. This API uses an asynchronous callback to return
...
@@ -1634,19 +1813,23 @@ Lists all files in a directory. This API uses an asynchronous callback to return
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -1685,24 +1868,28 @@ Lists all files in a directory synchronously. This API supports recursive listin
...
@@ -1685,24 +1868,28 @@ Lists all files in a directory synchronously. This API supports recursive listin
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| --------------------- | ---------- |
| --------------------- | ---------- |
| string[] | File names listed.|
| string[] | File names listed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -1734,17 +1921,21 @@ Moves a folder. This API uses a promise to return the result.
...
@@ -1734,17 +1921,21 @@ Moves a folder. This API uses a promise to return the result.
| src | string | Yes | Application sandbox path of the source folder.|
| src | string | Yes | Application sandbox path of the source folder.|
| dest | string | Yes | Application sandbox path of the destination folder.|
| dest | string | Yes | Application sandbox path of the destination folder.|
| mode | number | No | Mode for moving the folder. The default value is **0**.<br>- **0**: Throw an exception if the destination directory has folders of the same names with the source folder.<br>- **1**: Throw an exception if the destination directory has files of the same names with the source folder. All files without conflicts in the source folder are moved to the destination folder, and all files without conflicts in the destination folder are retained. The **data** in the error thrown provides information about the conflict files.<br>- **2**: Forcibly overwrite the files with the same names in the destination folder. The files with the the same names in the destination folder are overwritten forcibly; the files without conflicts in the destination folder are retained.<br>- **3**: Forcibly overwrite the destination folder. Move the source folder to the destination directory and make the destination folder completely the same as the source folder. All the original files in the destination folder are not retained.|
| mode | number | No | Mode for moving the folder. The default value is **0**.<br>- **0**: Throw an exception if the destination directory has folders of the same names with the source folder.<br>- **1**: Throw an exception if the destination directory has files of the same names with the source folder. All files without conflicts in the source folder are moved to the destination folder, and all files without conflicts in the destination folder are retained. The **data** in the error thrown provides information about the conflict files.<br>- **2**: Forcibly overwrite the files with the same names in the destination folder. The files with the the same names in the destination folder are overwritten forcibly; the files without conflicts in the destination folder are retained.<br>- **3**: Forcibly overwrite the destination folder. Move the source folder to the destination directory and make the destination folder completely the same as the source folder. All the original files in the destination folder are not retained.|
| src | string | Yes | Application sandbox path of the source folder.|
| src | string | Yes | Application sandbox path of the source folder.|
| dest | string | Yes | Application sandbox path of the destination folder.|
| dest | string | Yes | Application sandbox path of the destination folder.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The default value is **0**.<br>- **0**: Throw an exception if the destination directory has folders of the same names with the source folder.<br>- **1**: Throw an exception if the destination directory has files of the same names with the source folder. All files without conflicts in the source folder are moved to the destination folder, and all files without conflicts in the destination folder are retained. The **data** in the error thrown provides information about the conflict files.<br>- **2**: Forcibly overwrite the files with the same names in the destination folder. The files with the the same names in the destination folder are overwritten forcibly; the files without conflicts in the destination folder are retained.<br>- **3**: Forcibly overwrite the destination folder. Move the source folder to the destination directory and make the destination folder completely the same as the source folder. All the original files in the destination folder are not retained.|
| mode | number | No | Mode for moving the folder. The default value is **0**.<br>- **0**: Throw an exception if the destination directory has folders of the same names with the source folder.<br>- **1**: Throw an exception if the destination directory has files of the same names with the source folder. All files without conflicts in the source folder are moved to the destination folder, and all files without conflicts in the destination folder are retained. The **data** in the error thrown provides information about the conflict files.<br>- **2**: Forcibly overwrite the files with the same names in the destination folder. The files with the the same names in the destination folder are overwritten forcibly; the files without conflicts in the destination folder are retained.<br>- **3**: Forcibly overwrite the destination folder. Move the source folder to the destination directory and make the destination folder completely the same as the source folder. All the original files in the destination folder are not retained.|
| callback | AsyncCallback<void> | Yes | Callback invoked when the folder is moved. |
| callback | AsyncCallback<void> | Yes | Callback invoked when the folder is moved. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -1813,17 +2008,21 @@ Moves a file. This API uses a promise to return the result.
...
@@ -1813,17 +2008,21 @@ Moves a file. This API uses a promise to return the result.
| src | string | Yes | Application sandbox path of the source file.|
| src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| src | string | Yes | Application sandbox path of the source file.|
| src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| callback | AsyncCallback<void> | Yes | Callback invoked when the file is moved. |
| callback | AsyncCallback<void> | Yes | Callback invoked when the file is moved. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -1878,11 +2081,15 @@ Moves a file synchronously.
...
@@ -1878,11 +2081,15 @@ Moves a file synchronously.
| src | string | Yes | Application sandbox path of the source file.|
| src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -1903,15 +2110,19 @@ Creates a temporary directory. This API uses a promise to return the result.
...
@@ -1903,15 +2110,19 @@ Creates a temporary directory. This API uses a promise to return the result.
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | ---------- |
| ------ | ---------- |
| string | Unique path generated.|
| string | Unique path generated.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -1994,9 +2212,13 @@ Creates a stream based on the file path. This API uses a promise to return the r
...
@@ -1994,9 +2212,13 @@ Creates a stream based on the file path. This API uses a promise to return the r
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| --------------------------------- | --------- |
| --------------------------------- | --------- |
| Promise<[Stream](#stream)> | Promise used to return the result.|
| Promise<[Stream](#stream)> | Promise used to return the result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2026,6 +2248,10 @@ Creates a stream based on the file path. This API uses an asynchronous callback
...
@@ -2026,6 +2248,10 @@ Creates a stream based on the file path. This API uses an asynchronous callback
| 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).|
| 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).|
| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is created asynchronously. |
| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is created asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
```js
```js
...
@@ -2056,9 +2282,13 @@ Synchronously creates a stream based on the file path.
...
@@ -2056,9 +2282,13 @@ Synchronously creates a stream based on the file path.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------------------ | --------- |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
| [Stream](#stream) | Stream opened.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2072,22 +2302,26 @@ Synchronously creates a stream based on the file path.
...
@@ -2072,22 +2302,26 @@ Synchronously creates a stream based on the file path.
| 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).|
| 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).|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| --------------------------------- | --------- |
| --------------------------------- | --------- |
| Promise<[Stream](#stream)> | Promise used to return the result.|
| Promise<[Stream](#stream)> | Promise used to return the result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2102,22 +2336,25 @@ Opens a stream based on the file descriptor. This API uses a promise to return t
...
@@ -2102,22 +2336,25 @@ Opens a stream based on the file descriptor. This API uses a promise to return t
| 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).|
| 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).|
| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. |
| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2138,22 +2375,26 @@ Opens a stream based on the file descriptor. This API uses an asynchronous callb
...
@@ -2138,22 +2375,26 @@ Opens a stream based on the file descriptor. This API uses an asynchronous callb
| 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).|
| 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).|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------------------ | --------- |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
| [Stream](#stream) | Stream opened.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2176,17 +2417,21 @@ Creates a **Watcher** object to observe file or directory changes.
...
@@ -2176,17 +2417,21 @@ Creates a **Watcher** object to observe file or directory changes.
| path | string | Yes | Application sandbox path of the file or directory to observe. |
| path | string | Yes | Application sandbox path of the file or directory to observe. |
| events | number | Yes | Events to observe. Multiple events can be separated by a bitwise OR operator (|)|.<br>- **0x1: IN_ACCESS**: A file is accessed.<br>- **0x2: IN_MODIFY**: The file content is modified.<br>- **0x4: IN_ATTRIB**: Metadata is changed.<br>- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.<br>- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.<br>- **0x20: IN_OPEN**: A file or directory is opened.<br>- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.<br>- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.<br>- **0x100: IN_CREATE**: A file or directory is created in the observed directory.<br>- **0x200: IN_DELETE**: A file or directory is deleted from the observed directory.<br>- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.<br>- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.<br>- **0xfff: IN_ALL_EVENTS**: All events.|
| events | number | Yes | Events to observe. Multiple events can be separated by a bitwise OR operator (|)|.<br>- **0x1: IN_ACCESS**: A file is accessed.<br>- **0x2: IN_MODIFY**: The file content is modified.<br>- **0x4: IN_ATTRIB**: Metadata is changed.<br>- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.<br>- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.<br>- **0x20: IN_OPEN**: A file or directory is opened.<br>- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.<br>- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.<br>- **0x100: IN_CREATE**: A file or directory is created in the observed directory.<br>- **0x200: IN_DELETE**: A file or directory is deleted from the observed directory.<br>- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.<br>- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.<br>- **0xfff: IN_ALL_EVENTS**: All events.|
| listener | WatchEventListener | Yes | Callback invoked when an observed event occurs. The callback will be invoked each time an observed event occurs. |
| listener | WatchEventListener | Yes | Callback invoked when an observed event occurs. The callback will be invoked each time an observed event occurs. |
| event | WatchEvent | Yes | Event for the callback to invoke. |
| event | WatchEvent | Yes | Event for the callback to invoke. |
## WatchEvent<sup>10+</sup>
## WatchEvent<sup>10+</sup>
...
@@ -2255,7 +2500,6 @@ Represents detailed file information. Before calling any API of the **Stat()** c
...
@@ -2255,7 +2500,6 @@ Represents detailed file information. Before calling any API of the **Stat()** c
| 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. |
| 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. |
| 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. |
| 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. |
### isBlockDevice
### isBlockDevice
isBlockDevice(): boolean
isBlockDevice(): boolean
...
@@ -2266,9 +2510,13 @@ Checks whether this file is a block special file. A block special file supports
...
@@ -2266,9 +2510,13 @@ Checks whether this file is a block special file. A block special file supports
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | ---------------- |
| ------- | ---------------- |
| boolean | Whether the file is a block special file.|
| boolean | Whether the file is a block special file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2287,9 +2535,13 @@ Checks whether this file is a character special file. A character special file s
...
@@ -2287,9 +2535,13 @@ Checks whether this file is a character special file. A character special file s
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | ----------------- |
| ------- | ----------------- |
| boolean | Whether the file is a character special file.|
| boolean | Whether the file is a character special file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2298,7 +2550,6 @@ Checks whether this file is a character special file. A character special file s
...
@@ -2298,7 +2550,6 @@ Checks whether this file is a character special file. A character special file s
@@ -2331,9 +2585,13 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
...
@@ -2331,9 +2585,13 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | --------------------- |
| ------- | --------------------- |
| boolean | Whether the file is a FIFO.|
| boolean | Whether the file is a FIFO.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2342,7 +2600,6 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
...
@@ -2342,7 +2600,6 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
letisFIFO=fs.statSync(filePath).isFIFO();
letisFIFO=fs.statSync(filePath).isFIFO();
```
```
### isFile
### isFile
isFile(): boolean
isFile(): boolean
...
@@ -2353,9 +2610,13 @@ Checks whether this file is a regular file.
...
@@ -2353,9 +2610,13 @@ Checks whether this file is a regular file.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | --------------- |
| ------- | --------------- |
| boolean | Whether the file is a regular file.|
| boolean | Whether the file is a regular file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2364,7 +2625,6 @@ Checks whether this file is a regular file.
...
@@ -2364,7 +2625,6 @@ Checks whether this file is a regular file.
letisFile=fs.statSync(filePath).isFile();
letisFile=fs.statSync(filePath).isFile();
```
```
### isSocket
### isSocket
isSocket(): boolean
isSocket(): boolean
...
@@ -2375,9 +2635,13 @@ Checks whether this file is a socket.
...
@@ -2375,9 +2635,13 @@ Checks whether this file is a socket.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | -------------- |
| ------- | -------------- |
| boolean | Whether the file is a socket.|
| boolean | Whether the file is a socket.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2386,7 +2650,6 @@ Checks whether this file is a socket.
...
@@ -2386,7 +2650,6 @@ Checks whether this file is a socket.
letisSocket=fs.statSync(filePath).isSocket();
letisSocket=fs.statSync(filePath).isSocket();
```
```
### isSymbolicLink
### isSymbolicLink
isSymbolicLink(): boolean
isSymbolicLink(): boolean
...
@@ -2397,9 +2660,13 @@ Checks whether this file is a symbolic link.
...
@@ -2397,9 +2660,13 @@ Checks whether this file is a symbolic link.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | --------------- |
| ------- | --------------- |
| boolean | Whether the file is a symbolic link.|
| boolean | Whether the file is a symbolic link.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2412,7 +2679,6 @@ Checks whether this file is a symbolic link.
...
@@ -2412,7 +2679,6 @@ Checks whether this file is a symbolic link.
Provides a stream for file operations. Before calling any API of the **Stream** class, use **createStream()** to create a **Stream** instance synchronously or asynchronously.
Provides a stream for file operations. Before calling any API of the **Stream** class, use **createStream()** to create a **Stream** instance synchronously or asynchronously.
### close
### close
close(): Promise<void>
close(): Promise<void>
...
@@ -2423,9 +2689,13 @@ Closes the stream. This API uses a promise to return the result.
...
@@ -2423,9 +2689,13 @@ Closes the stream. This API uses a promise to return the result.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------------------- | ------------- |
| ------------------- | ------------- |
| Promise<void> | Promise used to return the stream close result.|
| Promise<void> | Promise used to return the stream close result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2439,7 +2709,6 @@ Closes the stream. This API uses a promise to return the result.
...
@@ -2439,7 +2709,6 @@ Closes the stream. This API uses a promise to return the result.
});
});
```
```
### close
### close
close(callback: AsyncCallback<void>): void
close(callback: AsyncCallback<void>): void
...
@@ -2450,9 +2719,13 @@ Closes the stream. This API uses an asynchronous callback to return the result.
...
@@ -2450,9 +2719,13 @@ Closes the stream. This API uses an asynchronous callback to return the result.
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (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.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (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.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| --------------------- | -------- |
| --------------------- | -------- |
| Promise<number> | Promise used to return the length of the data written.|
| Promise<number> | Promise used to return the length of the data written.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2588,7 +2880,6 @@ Writes data into the stream. This API uses a promise to return the result.
...
@@ -2588,7 +2880,6 @@ Writes data into the stream. This API uses a promise to return the result.
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (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.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (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.|
| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2631,16 +2926,20 @@ Synchronously writes data into the stream.
...
@@ -2631,16 +2926,20 @@ Synchronously writes data into the stream.
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (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.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (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.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | -------- |
| ------ | -------- |
| number | Length of the data written in the file.|
| number | Length of the data written in the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2660,16 +2959,20 @@ Reads data from the stream. This API uses a promise to return the result.
...
@@ -2660,16 +2959,20 @@ Reads data from the stream. This API uses a promise to return the result.
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ---------------------------------- | ------ |
| ---------------------------------- | ------ |
| Promise<number> | Promise used to return the data read.|
| Promise<number> | Promise used to return the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2685,7 +2988,6 @@ Reads data from the stream. This API uses a promise to return the result.
...
@@ -2685,7 +2988,6 @@ Reads data from the stream. This API uses a promise to return the result.
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
| callback | AsyncCallback<number> | Yes | Callback invoked when data is read asynchronously from the stream. |
| callback | AsyncCallback<number> | Yes | Callback invoked when data is read asynchronously from the stream. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2728,16 +3034,20 @@ Synchronously reads data from the stream.
...
@@ -2728,16 +3034,20 @@ Synchronously reads data from the stream.
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.<br> |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.<br> |
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | -------- |
| ------ | -------- |
| number | Length of the data read.|
| number | Length of the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
**Example**
...
@@ -2769,15 +3079,19 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
...
@@ -2769,15 +3079,19 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A