diff --git a/en/application-dev/reference/apis/js-apis-fileio.md b/en/application-dev/reference/apis/js-apis-fileio.md index 9b88c6a1bb9e4eeae87f45ca47c5bec6cc290842..67e1d8d19ef2eb70aa14c8a9a18e5281367b974f 100644 --- a/en/application-dev/reference/apis/js-apis-fileio.md +++ b/en/application-dev/reference/apis/js-apis-fileio.md @@ -1,6 +1,6 @@ # File Management -> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> 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. ## Modules to Import @@ -15,7 +15,7 @@ import fileio from '@ohos.fileio'; None -## Note +## Guidelines Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md). @@ -42,6 +42,8 @@ stat(path: string): Promise<Stat> Asynchronously obtains file information. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -68,6 +70,8 @@ stat(path:string, callback:AsyncCallback<Stat>): void Asynchronously obtains file information. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -88,6 +92,8 @@ statSync(path:string): Stat Synchronously obtains file information. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -112,6 +118,8 @@ opendir(path: string): Promise<Dir> Asynchronously opens a directory. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -138,6 +146,8 @@ opendir(path: string, callback: AsyncCallback<Dir>): void Asynchronously opens a directory. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -148,7 +158,7 @@ Asynchronously opens a directory. This method uses a callback to return the resu ```js fileio.opendir(path, function (err, dir) { // Example code in Dir struct - // Use read/readSync/close + // Use read/readSync/close. }); ``` @@ -159,6 +169,8 @@ opendirSync(path: string): Dir Synchronously opens a directory. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| @@ -184,11 +196,13 @@ access(path: string, mode?: number): Promise<void> Asynchronously checks whether the current process can access a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| + | mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| - Return value | Type| Description| @@ -207,15 +221,17 @@ Asynchronously checks whether the current process can access a file. This method ## fileio.access -access(path: String, mode?: number, callback: AsyncCallback<void>): void +access(path: string, mode: number, callback: AsyncCallback<void>): void Asynchronously checks whether the current process can access a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| + | mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| | callback | AsyncCallback<void> | Yes| Callback invoked when the file is asynchronously checked.| - Example @@ -232,12 +248,13 @@ accessSync(path: string, mode?: number): void Synchronously checks whether the current process can access the specified file. +**System capability**: SystemCapability.FileManagement.File.FileIO - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| + | mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| - Example ```js @@ -255,6 +272,8 @@ close(fd: number):Promise<void> Asynchronously closes a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -282,6 +301,8 @@ close(fd: number, callback:AsyncCallback<void>): void Asynchronously closes a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -303,6 +324,8 @@ closeSync(fd: number): void Synchronously closes a file. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -320,6 +343,8 @@ close(): Promise<void> Asynchronously closes the stream. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Return value | Type| Description| | -------- | -------- | @@ -341,6 +366,8 @@ close(callback: AsyncCallback<void>): void Asynchronously closes the stream. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -360,12 +387,14 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise<voi Asynchronously copies a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | src | string \| number | Yes| Path or file descriptor of the file to copy.| | dest | string \| number | Yes| Path or file descriptor of the new file.| - | mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| + | mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| - Return value | Type| Description| @@ -384,16 +413,18 @@ Asynchronously copies a file. This method uses a promise to return the result. ## fileio.copyFile -copyFile(src:string | number, dest:string | number, mode?: number, callback: AsyncCallbak<void>): void +copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback<void>): void Asynchronously copies a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | src | string \| number | Yes| Path or file descriptor of the file to copy.| | dest | string \| number | Yes| Path or file descriptor of the new file.| - | mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| + | mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: Completely 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.| - Example @@ -406,16 +437,18 @@ Asynchronously copies a file. This method uses a callback to return the result. ## fileio.copyFileSync -fileio.copyFileSync(src:string | number, dest:string | number, mode?:number): void +copyFileSync(src: string | number, dest: string | number, mode?: number): void Synchronously copies a file. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | src | string \| number | Yes| Path or file descriptor of the file to copy.| | dest | string \| number | Yes| Path or file descriptor of the new file.| - | mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| + | mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| - Example ```js @@ -429,12 +462,13 @@ mkdir(path:string, mode?: number): Promise<void> Asynchronously creates a directory. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the directory to create.| - | mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - Return value | Type| Description| @@ -453,15 +487,17 @@ Asynchronously creates a directory. This method uses a promise to return the res ## fileio.mkdir -mkdir(path:string, mode?:number, callback:AsyncCallbak<void>): void +mkdir(path: string, mode: number, callback: AsyncCallback<void>): void Asynchronously creates a directory. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the directory to create.| - | mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| | callback | AsyncCallback<void> | Yes| Callback invoked when the directory is created asynchronously.| - Example @@ -476,15 +512,17 @@ Asynchronously creates a directory. This method uses a callback to return the re ## fileio.mkdirSync -fileio.mkdirSync(path: string, mode?: number): void +mkdirSync(path: string, mode?: number): void Synchronously creates a directory. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the directory to create.| - | mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - Example ```js @@ -498,17 +536,19 @@ open(path: string, flags?: number, mode?: number): Promise<number> Asynchronously opens a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | flags | number | No| Option for opening a file. You must specify one of the following options. By default, the file is opened in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
You can also specify the following options, separated using a bitwise OR operator (|). By default, no extra option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.
- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| - | mode | number | No| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | 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.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| + | mode | number | No| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - Return value | Type| Description| | -------- | -------- | - | Promise<number> | Promise used to return the file descriptor of the file opened.| + | Promise<number> | File descriptor of the file opened.| - Example ```js @@ -526,12 +566,14 @@ open(path: string, flags: number, mode: number, callback: AsyncCallback<numbe Asynchronously opens a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | flags | number | Yes| Option for opening a file. You must specify one of the following options. By default, the file is opened in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
You can also specify the following options, separated using a bitwise OR operator (|). By default, no extra option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.
- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| - | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | flags | number | Yes| Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| + | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| | callback | AsyncCallback <void> | Yes| Callback invoked when the file is open asynchronously.| - Example @@ -548,12 +590,14 @@ openSync(path:string, flags?:number, mode?:number): number Synchronously opens a file. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | flags | number | No| Option for opening a file. You must specify one of the following options. By default, the file is opened in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
You can also specify the following options, separated using a bitwise OR operator (|). By default, no extra option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.
- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| - | mode | number | No| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.
The file permissions of newly created files are affected by **umask**, which is set as the process starts. Currently, the modification of **umask** is not open. + | 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.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| + | mode | number | No| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.
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.| - Return value | Type| Description| @@ -568,21 +612,27 @@ Synchronously opens a file. ## fileio.read -read(fd: number, buffer: ArrayBuffer, options?: Object): Promise<Readout> +read(fd: number, buffer: ArrayBuffer, options?: { + offset?: number; + length?: number; + position?: number; +}): Promise<ReadOut> Asynchronously reads data from a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the file to read.| | buffer | ArrayBuffer | Yes| Buffer used to store the file data read.| - | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to be read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to be read in the file. By default, data is read from the current position.| + | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.| - Return value | Type| Description| | -------- | -------- | - | Promise<[Readout](#readout)> | Promise used to return the data read.| + | Promise<[ReadOut](#readout)> | Data read.| - Example ```js @@ -598,17 +648,23 @@ Asynchronously reads data from a file. This method uses a promise to return the ## fileio.read -read(fd: number, buffer: ArrayBuffer, options?: Object, callback: AsyncCallback<Readout>): void +read(fd: number, buffer: ArrayBuffer, options: { + offset?: number; + length?: number; + position?: number; +}, callback: AsyncCallback<ReadOut>): void Asynchronously reads data from a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the file to read.| | buffer | ArrayBuffer | Yes| Buffer used to store the file data read.| - | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to be read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to be read in the file. By default, data is read from the current position.| - | callback | AsyncCallback<[Readout](#readout)> | Yes| Callback invoked when the data is read asynchronously.| + | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.| + | callback | AsyncCallback<[ReadOut](#readout)> | Yes| Callback invoked when the data is read asynchronously.| - Example ```js @@ -624,16 +680,22 @@ Asynchronously reads data from a file. This method uses a callback to return the ## fileio.readSync -readSync(fd: number, buffer: ArrayBuffer, options?: Object): number +readSync(fd: number, buffer: ArrayBuffer, options?: { + offset?: number; + length?: number; + position?: number; +}): number Synchronously reads data from a file. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the file to read.| | buffer | ArrayBuffer | Yes| Buffer used to store the file data read.| - | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to be read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to be read in the file. By default, data is read from the current position.| + | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.| - Return value | Type| Description| @@ -654,6 +716,8 @@ rmdir(path: string): Promise<void> Asynchronously deletes a directory. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -680,6 +744,8 @@ rmdir(path: string, callback:AsyncCallback<void>): void Asynchronously deletes a directory. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -694,12 +760,14 @@ Asynchronously deletes a directory. This method uses a callback to return the re ``` -## fileio.rmdirSync +## fileio.rmdirSync7+ -rmdirSync(path:string) +rmdirSync(path: string): void Synchronously deletes a directory. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -717,6 +785,8 @@ unlink(path:string): Promise<void> Asynchronously deletes a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -743,6 +813,8 @@ unlink(path:string, callback:AsyncCallback<void>): void Asynchronously deletes a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -765,6 +837,8 @@ unlinkSync(path: string): void Synchronously deletes a file. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -778,21 +852,28 @@ Synchronously deletes a file. ## fileio.write -write(fd: number, buffer: ArrayBuffer | string, options?: Object): Promise<number> +write(fd: number, buffer: ArrayBuffer | string, options?: { + offset?: number; + length?: number; + position?: number; + encoding?: string; +}): Promise<number> Asynchronously writes data into a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the file to write.| | 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:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **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:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| - Return value | Type| Description| | -------- | -------- | - | Promise<number> | Promise used to return the length of the data written in the file.| + | Promise<number> | Length of the data written in the file.| - Example ```js @@ -807,16 +888,23 @@ Asynchronously writes data into a file. This method uses a promise to return the ## fileio.write -write(fd:number, buffer:ArrayBuffer | string,options?:Object, callback:AsyncCallback<number>): void +write(fd: number, buffer: ArrayBuffer | string, options: { + offset?: number; + length?: number; + position?: number; + encoding?: string; +}, callback: AsyncCallback<number>): void Asynchronously writes data into a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the file to write.| | 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:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **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:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| | callback | AsyncCallback<number> | Yes| Callback invoked when the data is written asynchronously.| - Example @@ -832,16 +920,23 @@ Asynchronously writes data into a file. This method uses a callback to return th ## fileio.writeSync -writeSync(fd: number, buffer: ArrayBuffer | string, options?:Object): number +writeSync(fd: number, buffer: ArrayBuffer | string, options?: { + offset?: number; + length?: number; + position?: number; + encoding?: string; +}): number Synchronously writes data into a file. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the file to write.| | 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:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **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:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| - Return value | Type| Description| @@ -861,6 +956,8 @@ hash(path: string, algorithm: string): Promise<string> Asynchronously calculates the hash value of a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -884,10 +981,12 @@ Asynchronously calculates the hash value of a file. This method uses a promise t ## fileio.hash -hash(psth:string, algorithm:string, callback:AsyncCallback<string>): void +hash(path: string, algorithm: string, callback: AsyncCallback<string>): void Asynchronously calculates the hash value of a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -911,11 +1010,13 @@ chmod(path: string, mode: number):Promise<void> Asynchronously changes the file permissions based on its path. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - Return value | Type| Description| @@ -938,11 +1039,13 @@ chmod(path: string, mode: number, callback: AsyncCallback<void>): void Asynchronously changes the file permissions based on its path. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| | callback | AsyncCallback<void> | Yes| Callback invoked when the file permissions are changed asynchronously.| - Example @@ -959,11 +1062,13 @@ chmodSync(path: string, mode: number): void Synchronously changes the file permissions based on its path. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - Example ```js @@ -977,6 +1082,8 @@ fstat(fd: number): Promise<Stat> Asynchronously obtains file status information based on the file descriptor. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -985,7 +1092,7 @@ Asynchronously obtains file status information based on the file descriptor. Thi - Return value | Type| Description| | -------- | -------- | - | Promise<[Stat](#stat)> | Promise used to return the file status information.| + | Promise<[Stat](#stat)> | Promise used to return the file status information obtained.| - Example ```js @@ -1003,6 +1110,8 @@ fstat(fd: number, callback: AsyncCallback<Stat>): void Asynchronously obtains file status information based on the file descriptor. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1024,6 +1133,8 @@ fstatSync(fd: number): Stat Synchronously obtains file status information based on the file descriptor. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1043,10 +1154,12 @@ Synchronously obtains file status information based on the file descriptor. ## fileio.ftruncate7+ -ftruncate(fd: number, len: number): Promise<void> +ftruncate(fd: number, len?: number): Promise<void> Asynchronously truncates a file based on the file descriptor. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1062,7 +1175,7 @@ Asynchronously truncates a file based on the file descriptor. This method uses a ```js let fd = fileio.openSync(path); fileio.ftruncate(fd, 5).then(function(err) { - console.info("File truncated successfully"); + console.info("File truncated successfully."); }).catch(function(err){ console.info("Failed to truncate the file. Error:"+ err); }); @@ -1075,6 +1188,8 @@ ftruncate(fd: number, len: number, callback:AsyncCallback<void>): void Asynchronously truncates a file based on the file descriptor. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1096,6 +1211,8 @@ ftruncateSync(fd: number, len?: number): void Synchronously truncates a file based on the file descriptor. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1110,10 +1227,12 @@ Synchronously truncates a file based on the file descriptor. ## fileio.truncate7+ -truncate(path: string, len: number): Promise<void> +truncate(path: string, len?: number): Promise<void> Asynchronously truncates a file based on its path. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1128,7 +1247,7 @@ Asynchronously truncates a file based on its path. This method uses a promise to - Example ```js fileio.truncate(path, len).then(function(){ - console.info("File truncated successfully"); + console.info("File truncated successfully."); }).catch(function(err){ console.info("Failed to truncate the file. Error:"+ err); }); @@ -1141,6 +1260,8 @@ truncate(path: string, len: number, callback:AsyncCallback<void>): void Asynchronously truncates a file based on its path. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1158,10 +1279,12 @@ Asynchronously truncates a file based on its path. This method uses a callback t ## fileio.truncateSync7+ -truncateSync(fpath: string, len?: number): void +truncateSync(path: string, len?: number): void Synchronously truncates a file based on the file path. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1176,15 +1299,21 @@ Synchronously truncates a file based on the file path. ## fileio.readText7+ -readText(filePath: string, options?:Object): Promise<string> +readText(filePath: string, options?: { + position?: number; + length?: number; + encoding?: string; +}): Promise<string> Asynchronously reads the text of a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | filePath | string | Yes| Absolute path of the file to read.| - | options | Object | No| The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to be read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| + | options | Object | No| The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| - Return value | Type| Description| @@ -1203,15 +1332,21 @@ Asynchronously reads the text of a file. This method uses a promise to return th ## fileio.readText7+ -readText(filePath: string, options?:Object, callback:AsyncCallback<string>): void +readText(filePath: string, options: { + position?: number; + length?: number; + encoding?: string; +}, callback: AsyncCallback<string>): void Asynchronously reads the text of a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | filePath | string | Yes| Absolute path of the file to read.| - | options | Object | No| The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to be read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| + | options | Object | No| The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| | callback | AsyncCallback<string> | Yes| Callback invoked when the file is read asynchronously.| - Example @@ -1224,20 +1359,26 @@ Asynchronously reads the text of a file. This method uses a callback to return t ## fileio.readTextSync7+ -readTextSync(filePath: string, options?:Object): string +readTextSync(filePath: string, options?: { + position?: number; + length?: number; + encoding?: string; +}): string Synchronously reads the text of a file. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | filePath | string | Yes| Absolute path of the file to read.| - | options | Object | No| The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to be read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| + | options | Object | No| The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| - Return value | Type| Description| | -------- | -------- | - | string| Content of the file read.| + | <string>| Content of the file read.| - Example ```js @@ -1251,6 +1392,8 @@ lstat(path: string): Promise<Stat> Asynchronously obtains link status information. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1259,7 +1402,7 @@ Asynchronously obtains link status information. This method uses a promise to re - Return value | Type| Description| | -------- | -------- | - | Promise<[Stat](#stat)> | Promise used to return the link status.| + | Promise<[Stat](#stat)> | Promise used to return the link status obtained.| - Example ```js @@ -1277,6 +1420,8 @@ lstat(path:string, callback:AsyncCallback<Stat>): void Asynchronously obtains link status information. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1287,7 +1432,7 @@ Asynchronously obtains link status information. This method uses a callback to r ```js fileio.lstat(path, function (err, stat) { // Do something. - )); + }); ``` @@ -1297,6 +1442,8 @@ lstatSync(path:string): Stat Synchronously obtains link status information. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1305,7 +1452,7 @@ Synchronously obtains link status information. - Return value | Type| Description| | -------- | -------- | - | [Stat](#stat) | Link status information.| + | [Stat](#stat) | Link status obtained.| - Example ```js @@ -1315,20 +1462,26 @@ Synchronously obtains link status information. ## fileio.read7+ -read(buffer: ArrayBuffer, options?: Object): Promise<Readout> +read(buffer: ArrayBuffer, options?: { + position?: number; + offset?: number; + length?: number; +}): Promise<ReadOut> Asynchronously reads data from a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | buffer | ArrayBuffer | Yes| Buffer used to store the file data read.| - | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to be read. It is optional. The default value is the buffer length minus the offset.| + | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.| - Return value | Type| Description| | -------- | -------- | - | Promise<[Readout](#readout)> | Promise used to return the data read.| + | Promise<[ReadOut](#readout)> | Data read.| - Example ```js @@ -1342,16 +1495,22 @@ Asynchronously reads data from a file. This method uses a promise to return the ## fileio.read7+ -read(buffer: ArrayBuffer, options?: Object, callback: AsyncCallback<Readout>): void +read(buffer: ArrayBuffer, options: { + position?: number; + offset?: number; + length?: number; +}, callback: AsyncCallback<ReadOut>): void Asynchronously reads data from a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | buffer | ArrayBuffer | Yes| Buffer used to store the file data read.| - | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to be read. It is optional. The default value is the buffer length minus the offset.| - | callback | AsyncCallback<[Readout](#readout)> | Yes| Callback invoked when the data is read asynchronously from the file.| + | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.| + | callback | AsyncCallback<[ReadOut](#readout)> | Yes| Callback invoked when the data is read asynchronously from the file.| - Example ```js @@ -1370,6 +1529,8 @@ rename(oldPath: string, newPath: string): Promise<void> Asynchronously renames a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1397,6 +1558,8 @@ rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): v Asynchronously renames a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1417,6 +1580,8 @@ renameSync(oldPath: string, newPath: string): void Synchronously renames a file. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1435,6 +1600,8 @@ fsync(fd: number): Promise<void> Asynchronously synchronizes a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1461,6 +1628,8 @@ fsync(fd: number, callback: AsyncCallback<void>): void Asynchronously synchronizes a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1479,7 +1648,9 @@ Asynchronously synchronizes a file. This method uses a callback to return the re fsyncSync(fd: number): void -Synchronizes a file in synchronous mode. +Synchronizes a file in synchronous mode. + +**System capability**: SystemCapability.FileManagement.File.FileIO - Parameters | Name| Type| Mandatory| Description| @@ -1498,6 +1669,8 @@ fdatasync(fd: number): Promise<void> Asynchronously synchronizes data in a file. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1524,6 +1697,8 @@ fdatasync(fd: number, callback:AsyncCallback<void>): void Asynchronously synchronizes data in a file. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1544,6 +1719,8 @@ fdatasyncSync(fd: number): void Synchronizes data in a file in synchronous mode. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1561,6 +1738,8 @@ symlink(target: string, srcPath: string): Promise<void> Asynchronously creates a symbolic link based on a path. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1588,6 +1767,8 @@ symlink(target: string, srcPath: string, callback: AsyncCallback<void>): v Asynchronously creates a symbolic link based on a path. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1609,6 +1790,8 @@ symlinkSync(target: string, srcPath: string): void Synchronously creates a symbolic link based on a specified path. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1627,6 +1810,8 @@ chown(path: string, uid: number, gid: number): Promise<void> Asynchronously changes the file owner based on its path. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1642,7 +1827,7 @@ Asynchronously changes the file owner based on its path. This method uses a prom - Example ```js let stat = fileio.statSync(path); - fileio.chown(path, stat.uid, stat.gid)).then(function(){ + fileio.chown(path, stat.uid, stat.gid).then(function(){ console.info("chown successfully"); }).catch(function(err){ console.info("chown failed with error:"+ err); @@ -1656,6 +1841,8 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback<void> Asynchronously changes the file owner based on its path. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1679,6 +1866,8 @@ chownSync(path: string, uid: number, gid: number): void Synchronously changes the file owner based on its path. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1699,6 +1888,8 @@ mkdtemp(prefix: string): Promise<string> Asynchronously creates a temporary directory. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1707,7 +1898,7 @@ Asynchronously creates a temporary directory. This method uses a promise to retu - Return value | Name| Description| | -------- | -------- | - | Promise<string> | Promise used to return the unique path generated.| + | Promise<string> | Unique path generated.| - Example ```js @@ -1725,6 +1916,8 @@ mkdtemp(prefix: string, callback: AsyncCallback<string>): void Asynchronously creates a temporary directory. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1745,6 +1938,8 @@ mkdtempSync(prefix: string): string Synchronously creates a temporary directory. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -1767,11 +1962,13 @@ fchmod(fd: number, mode: number): Promise<void> Asynchronously changes the file permissions based on the file descriptor. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the target file.| - | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - Return value | Name| Description| @@ -1794,11 +1991,13 @@ fchmod(fd: number, mode: number, callback: AsyncCallback<void>): void Asynchronously changes the file permissions based on the file descriptor. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the target file.| - | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| | callback | AsyncCallback <void> | Yes| Callback invoked when the file permissions are changed asynchronously.| - Example @@ -1811,15 +2010,17 @@ Asynchronously changes the file permissions based on the file descriptor. This m ## fileio.fchmodSync7+ -fchmodSync(existingPath: string, newPath: string): void +fchmodSync(fd: number, mode: number): void Synchronously changes the file permissions based on the file descriptor. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the target file.| - | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - Example ```js @@ -1833,11 +2034,13 @@ createStream(path: string, mode: string): Promise<Stream> Asynchronously opens a stream based on the file path. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | mode | string | Yes| - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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 | Type| Description| @@ -1860,11 +2063,13 @@ createStream(path: string, mode: string, callback: AsyncCallback<Stream>): Asynchronously opens a stream based on the file path. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | mode | string | Yes| - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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](#stream7)> | Yes| Callback invoked when the stream is open asynchronously.| - Example @@ -1881,16 +2086,18 @@ createStreamSync(path: string, mode: string): Stream Synchronously opens a stream based on the file path. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Absolute path of the target file.| - | mode | string | Yes| - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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 | Name| Description| | -------- | -------- | - | [Stream](#stream7) | Stream obtained.| + | [Stream](#stream7) | Stream opened.| - Example ```js @@ -1904,11 +2111,13 @@ fdopenStream(fd: number, mode: string): Promise<Stream> Asynchronously opens a stream based on the file descriptor. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the target file.| - | mode | string | Yes| - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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 | Name| Description| @@ -1918,7 +2127,7 @@ Asynchronously opens a stream based on the file descriptor. This method uses a p - Example ```js fileio.fdopenStream(fd, mode).then(function(stream){ - console.info("openStream successfully"+); + console.info("openStream successfully"); }).catch(function(err){ console.info("openStream failed with error:"+ err); }); @@ -1931,11 +2140,13 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): v Asynchronously opens a stream based on the file descriptor. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the target file.| - | mode | string | Yes| - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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](#stream7)> | Yes| Callback invoked when the stream is open asynchronously.| - Example @@ -1952,16 +2163,18 @@ fdopenStreamSync(fd: number, mode: string): Stream Synchronously opens a stream based on the file descriptor. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fd | number | Yes| File descriptor of the target file.| - | mode | string | Yes| - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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 | Name| Description| | -------- | -------- | - | [Stream](#stream7) | Stream operation result.| + | [Stream](#stream7) | Stream opened.| - Example ```js @@ -1975,6 +2188,8 @@ fchown(fd: number, uid: number, gid: number): Promise<void> Asynchronously changes the file owner based on the file descriptor. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -2004,6 +2219,8 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback<void> Asynchronously changes the file owner based on the file descriptor. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -2027,6 +2244,8 @@ fchownSync(fd: number, uid: number, gid: number): void Synchronously changes the file owner based on the file descriptor. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -2047,6 +2266,8 @@ lchown(path: string, uid: number, gid: number): Promise<void> Asynchronously changes the file owner based on the file path, changes the owner of the symbolic link (not the referenced file), and returns the result in a promise. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -2076,6 +2297,8 @@ lchown(path: string, uid: number, gid: number, callback: AsyncCallback<void&g Asynchronously changes the file owner based on the file path, changes the owner of the symbolic link (not the referenced file), and returns the result in a callback. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -2099,6 +2322,8 @@ lchownSync(path: string, uid: number, gid: number): void Synchronously changes the file owner based on the file path and changes the owner of the symbolic link (not the referenced file). +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -2119,11 +2344,13 @@ createWatcher(filename: string, events: number, callback: AsyncCallback<numbe Asynchronously listens for the changes of a file or directory. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | filename | string | Yes| Absolute path of the target file.| - | events | Number | Yes| - **1**: : The file or directory is renamed.
- **2**: The file or directory is modified.
- **3**: The file or directory is modified and renamed.| + | events | Number | Yes| - **1**: The file or directory is renamed.
- **2**: The file or directory is modified.
- **3**: The file or directory is modified and renamed.| | callback | AsyncCallback<number > | Yes| Called each time a change is detected.| - Return value @@ -2143,6 +2370,8 @@ Asynchronously listens for the changes of a file or directory. This method uses Obtains the file read result. This class applies only to the **read()** method. +**System capability**: SystemCapability.FileManagement.File.FileIO + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | bytesRead | number | Yes| Yes| Length of the data read.| @@ -2154,6 +2383,7 @@ Obtains the file read result. This class applies only to the **read()** method. Provides detailed file information. Before calling a method of the **Stat** class, use the [stat()](#fileiostat) method synchronously or asynchronously to create a **Stat** instance. +**System capability**: SystemCapability.FileManagement.File.FileIO ### Attributes @@ -2161,7 +2391,7 @@ Provides detailed file information. Before calling a method of the **Stat** clas | -------- | -------- | -------- | -------- | -------- | | dev | number | Yes| No| Major device number.| | ino | number | Yes| No| File ID. Different files on the same device have different **ino**s.| -| 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:
- **0o170000**: mask used to obtain the file type.
- **0o140000**: The file is a socket.
- **0o120000**: The file is a symbolic link.
- **0o100000**: The file is a regular file.
- **0o060000**: The file is a block device.
- **0o040000**: The file is a directory.
- **0o020000**: The file is a character device.
- **0o010000**: The file is a named pipe (FIFO).
- **0o0700**: mask used to obtain the owner permissions.
- **0o0400**: The owner has the permission to read a regular file or a directory entry.
- **0o0200**: The owner has the permission to write a regular file or create and delete a directory entry.
- **0o0100**: The owner has the permission to execute a regular file or search for the specified path in a directory.
- **0o0070**: mask used to obtain the user group permissions.
- **0o0040**: The user group has the permission to read a regular file or a directory entry.
- **0o0020**: The user group has the permission to write a regular file or create and delete a directory entry.
- **0o0010**: The user group has the permission to execute a regular file or search for the specified path in a directory.
- **0o0007**: mask used to obtain the permissions of other users.
- **0o0004**: Other users have the permission to read a regular file or a directory entry.
- **0o0002**: Other users have the permission to write a regular file or create and delete a directory entry.
- **0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| +| 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:
- **0o170000**: mask used to obtain the file type.
- **0o140000**: The file is a socket.
- **0o120000**: The file is a symbolic link.
- **0o100000**: The file is a regular file.
- **0o060000**: The file is a block device.
- **0o040000**: The file is a directory.
- **0o020000**: The file is a character device.
- **0o010000**: The file is a named pipe (FIFO).
- **0o0700**: mask used to obtain the owner permissions.
- **0o0400**: The owner has the permission to read a regular file or a directory entry.
- **0o0200**: The owner has the permission to write a regular file or create and delete a directory entry.
- **0o0100**: The owner has the permission to execute a regular file or search for the specified path in a directory.
- **0o0070**: mask used to obtain the user group permissions.
- **0o0040**: The user group has the permission to read a regular file or a directory entry.
- **0o0020**: The user group has the permission to write a regular file or create and delete a directory entry.
- **0o0010**: The user group has the permission to execute a regular file or search for the specified path in a directory.
- **0o0007**: mask used to obtain the permissions of other users.
- **0o0004**: Other users have the permission to read a regular file or a directory entry.
- **0o0002**: Other users have the permission to write a regular file or create and delete a directory entry.
- **0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| | nlink | number | Yes| No| Number of hard links in the file.| | uid | number | Yes| No| User ID, that is ID of the file owner.| | gid | number | Yes| No| Group ID, that is, ID of the user group of the file.| @@ -2179,6 +2409,8 @@ isBlockDevice(): boolean Checks whether the current directory entry is a block special file. A block special file supports access by block only, and it is cached when accessed. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Return value | Type| Description| | -------- | -------- | @@ -2196,6 +2428,8 @@ isCharacterDevice(): boolean Checks whether the current directory entry is a character special file. A character special file supports random access, and it is not cached when accessed. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Return value | Type| Description| | -------- | -------- | @@ -2213,6 +2447,8 @@ isDirectory(): boolean Checks whether a directory entry is a directory. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Return value | Type| Description| | -------- | -------- | @@ -2230,6 +2466,8 @@ isFIFO(): boolean Checks whether the current directory entry is a named pipe (or FIFO). Named pipes are used for inter-process communication. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Return value | Type| Description| | -------- | -------- | @@ -2247,6 +2485,8 @@ isFile(): boolean Checks whether a directory entry is a regular file. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Return value | Type| Description| | -------- | -------- | @@ -2264,6 +2504,8 @@ isSocket(): boolean Checks whether a directory entry is a socket. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Return value | Type| Description| | -------- | -------- | @@ -2281,6 +2523,8 @@ isSymbolicLink(): boolean Checks whether a directory entry is a symbolic link. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Return value | Type| Description| | -------- | -------- | @@ -2299,10 +2543,12 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy ### stop7+ -stop(): void +stop(): Promise<void> Asynchronously stops **watcher**. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Example ```js fileio.stop(); @@ -2311,10 +2557,12 @@ Asynchronously stops **watcher**. This method uses a promise to return the resul ### stop7+ -stop(callback: AsyncCallback): void +stop(callback: AsyncCallback<void>): void Asynchronously stops **watcher**. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.File.FileIO + - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -2326,488 +2574,3 @@ Asynchronously stops **watcher**. This method uses a callback to return the resu // Do something. }); ``` -## Stream7+ - -File stream. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance. - - -### close7+ - -close(): Promise<void> - -Asynchronously closes the stream. This method uses a promise to return the result. - -- Return value - | Type| Description| - | -------- | -------- | - | Promise<void> | Promise used to return the stream close result.| - -- Example - ```js - let ss= fileio.createStreamSync(path); - ss.close().then(function(){ - console.info("close fileStream successfully"); - }).catch(function(err){ - console.info("close fileStream failed with error:"+ err); - }); - ``` - - -### close7+ - -close(callback: AsyncCallback<void>): void - -Asynchronously closes the stream. This method uses a callback to return the result. - -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | Yes| Callback invoked when the stream is closed asynchronously.| - -- Example - ```js - let ss= fileio.createStreamSync(path); - ss.close(function (err) { - // do something - }); - ``` - - -### closeSync7+ - -closeSync(): void - -Synchronously closes the stream. - -- Example - ```js - let ss= fileio.createStreamSync(path); - ss.closeSync(); - ``` - - -### flush7+ - -flush(): Promise<void> - -Asynchronously flushes the stream. This method uses a promise to return the result. - -- Return value - | Type| Description| - | -------- | -------- | - | Promise<void> | Promise used to return the stream flushing result.| - -- Example - ```js - let ss= fileio.createStreamSync(path); - ss.flush().then(function (){ - console.info("flush successfully"); - }).catch(function(err){ - console.info("flush failed with error:"+ err); - }); - ``` - - -### flush7+ - -flush(callback: AsyncCallback<void>): void - -Asynchronously flushes the stream. This method uses a callback to return the result. - -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | Yes| Callback invoked when the stream is asynchronously flushed.| - -- Example - ```js - let ss= fileio.createStreamSync(path); - ss.flush(function (err) { - // do something - }); - ``` - - -### flushSync7+ - -flushSync(): void - -Synchronously flushes the stream. - -- Example - ```js - let ss= fileio.createStreamSync(path); - ss.flushSync(); - ``` - - -### write7+ - -write(buffer: ArrayBuffer | string, options?: Object): Promise<number> - -Asynchronously writes data into the stream. This method uses a promise to return the result. - -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | 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:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| - -- Return value - | Type| Description| - | -------- | -------- | - | Promise<number> | Promise used to return the length of the data written in the file.| - -- Example - ```js - let ss= fileio.createStreamSync(fpath, "r+"); - ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){ - console.info("write successfully:"+ number); - }).catch(function(err){ - console.info("write failed with error:"+ err); - }); - ``` - - -### write7+ - -write(buffer:ArrayBuffer | string,options?:Object, callback:AsyncCallback<number>): void - -Asynchronously writes data into the stream. This method uses a callback to return the result. - -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | 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:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| - | callback | AsyncCallback<number> | Yes| Callback invoked when the data is written asynchronously.| - -- Example - ```js - let ss= fileio.createStreamSync(fpath, "r+"); - ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) { - if (!err) { - // do something - console.log(bytesWritten); - } - }); - ``` - - -### writeSync7+ - -writeSync(buffer: ArrayBuffer | string, options?:Object): number - -Synchronously writes data into the stream. - -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | 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:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| - -- Return value - | Type| Description| - | -------- | -------- | - | number | Length of the data written in the file.| - -- Example - ```js - let ss= fileio.createStreamSync(fpath,"r+"); - let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}); - ``` - - -### read7+ - -read(buffer: ArrayBuffer, options?: Object): Promise<Readout> - -Asynchronously reads data from the stream. This method uses a promise to return the result. - -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer | Yes| Buffer used to store the file read.| - | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to be read in the file. By default, data is read from the current position.| - -- Return value - | Type| Description| - | -------- | -------- | - | Promise<[Readout](#readout)> | Promise used to return the data read.| - -- Example - ```js - let ss = fileio.createStreamSync(fpath, "r+"); - ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){ - console.info("read data successfully"); - }).catch(function(err){ - console.info("read data failed with error:"+ err); - }); - ``` - - -### read7+ - -read(buffer: ArrayBuffer, options?: Object, callback: AsyncCallback<Readout>): void - -Asynchronously reads data from the stream. This method uses a callback to return the result. - -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer | Yes| Buffer used to store the file read.| - | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to be read in the file. By default, data is read from the current position.| - | callback | AsyncCallback<[Readout](#readout)> | Yes| Callback invoked when data is read asynchronously from the stream.| - -- Example - ```js - let ss = fileio.createStreamSync(fpath, "r+"); - ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) { - if (!err) { - // do something - } - }); - ``` - - -### readSync7+ - -readSync(buffer: ArrayBuffer, options?: Object): number - -Synchronously reads data from the stream. - -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer | Yes| Buffer used to store the file read.| - | options | Object | No| The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to be read in the file. By default, data is read from the current position.| - -- Return value - | Type| Description| - | -------- | -------- | - | number | Length of the data read.| - -- Example - ```js - let ss = fileio.createStreamSync(fpath, "r+"); - let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); - ``` - - -## Dir - -Manages directories. Before calling a method of the **Dir** class, use the [opendir()](#fileioopendir) method synchronously or asynchronously to create a **Dir** instance. - - -### read - -read(): Promise<Dirent> - -Asynchronously reads the next directory entry. This method uses a promise to return the result. - -- Return value - | Type| Description| - | -------- | -------- | - | Promise<[Dirent](#dirent)> | Directory entry that is read asynchronously.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - dir.read().then(function (dirent){ - console.info("read successfully:"+ dirent.name); - }).catch(function(err){ - console.info("read failed with error:"+ err); - }); - ``` - - -### read - -read(callback: AsyncCallback<Dirent>): void - -Asynchronously reads the next directory entry. This method uses a callback to return the result. - -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[Dirent](#dirent)> | Yes| Callback invoked when the next directory entry is asynchronously read.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - dir.read(function (err, dirent) { - if (!err) { - // do something - console.log(dirent.name) - } - }); - ``` - - -### readSync - -readSync(): Dirent - -Synchronously reads the next directory entry. - -- Return value - | Type| Description| - | -------- | -------- | - | [Dirent](#dirent) | Directory entry read.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - let dirent = dir.readSync(); - ``` - - -### closeSync - -closeSync(): void - -Closes a directory. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir. - -- Example - ```js - let dir = fileio.opendirSync(dpath); - dir.closeSync(); - ``` - - -## Dirent - -Provides 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. - - -### Attributes - -| Name| Type| Readable| Writable| Description| -| -------- | -------- | -------- | -------- | -------- | -| name | string | Yes| No| Directory entry name.| - - -### isBlockDevice - -isBlockDevice(): boolean - -Checks whether the current directory entry is a block special file. A block special file supports access by block only, and it is cached when accessed. - -- Return value - | Type| Description| - | -------- | -------- | - | boolean | Whether the directory entry is a block special file.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - let isBLockDevice = dir.readSync().isBlockDevice(); - ``` - - -### isCharacterDevice - -isCharacterDevice(): boolean - -Checks whether a directory entry is a character special file. A character special file supports random access, and it is not cached when accessed. - -- Return value - | Type| Description| - | -------- | -------- | - | boolean | Whether the directory entry is a character special file.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - let isCharacterDevice = dir.readSync().isCharacterDevice(); - ``` - - -### isDirectory - -isDirectory(): boolean - -Checks whether a directory entry is a directory. - -- Return value - | Type| Description| - | -------- | -------- | - | boolean | Whether the directory entry is a directory.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - let isDirectory = dir.readSync().isDirectory(); - ``` - - -### isFIFO - -isFIFO(): boolean - -Checks whether the current directory entry is a named pipe (or FIFO). Named pipes are used for inter-process communication. - -- Return value - | Type| Description| - | -------- | -------- | - | boolean | Whether the directory entry is a FIFO.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - let isFIFO = dir.readSync().isFIFO(); - ``` - - -### isFile - -isFile(): boolean - -Checks whether a directory entry is a regular file. - -- Return value - | Type| Description| - | -------- | -------- | - | boolean | Whether the directory entry is a regular file.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - let isFile = dir.readSync().isFile(); - ``` - - -### isSocket - -isSocket(): boolean - -Checks whether a directory entry is a socket. - -- Return value - | Type| Description| - | -------- | -------- | - | boolean | Whether the directory entry is a socket.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - let isSocket = dir.readSync().isSocket(); - ``` - - -### isSymbolicLink - -isSymbolicLink(): boolean - -Checks whether a directory entry is a symbolic link. - -- Return value - | Type| Description| - | -------- | -------- | - | boolean | Whether the directory entry is a symbolic link.| - -- Example - ```js - let dir = fileio.opendirSync(dpath); - let isSymbolicLink = dir.readSync().isSymbolicLink(); - ``` diff --git a/en/application-dev/reference/apis/js-apis-statfs.md b/en/application-dev/reference/apis/js-apis-statfs.md index 487903b87178466ff990eea4a8518a8fe58242ce..137f4cbc55ee2a9e0631e9f94e0244730a14ac87 100644 --- a/en/application-dev/reference/apis/js-apis-statfs.md +++ b/en/application-dev/reference/apis/js-apis-statfs.md @@ -1,6 +1,6 @@ # statfs -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE:** +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE:**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import @@ -9,7 +9,7 @@ import statfs from '@ohos.statfs'; ``` -## Note +## Guidelines Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md). @@ -21,27 +21,25 @@ For example, if the application directory obtained by using **getOrCreateLocalDi let path = dir + "xxx.txt"; ``` -## System Capabilities - -SystemCapability.FileManagement.File.FileIO - ## statfs.getFreeBytes getFreeBytes(path:string):Promise<number> Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.FileManagement.File.FileIO + +- **Parameters** - | Name| Type| Mandatory| Description| + | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ---------------------------- | - | path | string | Yes| File path of the file system.| + | path | string | Yes | File path of the file system.| -- Return values +- Return value - | Type| Description| + | Type | Description | | --------------------- | -------------- | - | Promise<number> | Number of free bytes obtained.| + | Promise<number> | Promise used to return the number of free bytes obtained.| - Example @@ -60,38 +58,42 @@ getFreeBytes(path:string, callback:AsyncCallback<number>): void Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a callback to return the result. -- Parameters +**System capability**: SystemCapability.FileManagement.File.FileIO - | Name| Type| Mandatory| Description| +- **Parameters** + + | Name | Type | Mandatory| Description | | -------- | --------------------------- | ---- | ---------------------------- | - | path | string | Yes| File path of the file system.| - | callback | AsyncCallback<number> | Yes| Callback invoked to return the number of free bytes obtained.| + | path | string | Yes | File path of the file system.| + | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of free bytes obtained.| - Example ```js statfs.getFreeBytes(path, function(err, number){ - // Do something. + //do something }); ``` ## statfs.getTotalBytes -getTotalBytes.(path:string):Promise<number> +getTotalBytes(path: string): Promise<number> Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a promise to return the result. -- Parameters +**System capability**: SystemCapability.FileManagement.File.FileIO + +- **Parameters** - | Name| Type| Mandatory| Description| + | Name| Type | Mandatory| Description | | ---- | ------ | ---- | ---------------------------- | - | path | string | Yes| File path of the file system.| + | path | string | Yes | File path of the file system.| -- Return values +- Return value - | Type| Description| + | Type | Description | | --------------------- | ------------ | - | Promise<number> | Total number of bytes obtained.| + | Promise<number> | Promise used to return the total number of bytes obtained.| - Example @@ -106,21 +108,23 @@ Obtains the total number of bytes of the specified file system in asynchronous m ## statfs.getTotalBytes -getTotalBytes(path:string, callback:AsyncCallback<number>): void +getTotalBytes(path: string, callback: AsyncCallback<number>): void Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a callback to return the result. -- Parameters +**System capability**: SystemCapability.FileManagement.File.FileIO + +- **Parameters** - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------- | --------------------------- | ---- | ---------------------------- | - | path | string | Yes| File path of the file system.| - | callback | AsyncCallback<number> | Yes| Callback invoked to return the total number of bytes obtained.| + | path | string | Yes | File path of the file system.| + | callback | AsyncCallback<number> | Yes | Callback invoked to return the total number of bytes obtained. | - Example ```js statfs.getTotalBytes(path, function(err, number){ - // Do something. + //do something }); ``` diff --git a/en/application-dev/reference/apis/js-apis-volumemanager.md b/en/application-dev/reference/apis/js-apis-volumemanager.md index 736d206d573b17b20d1cdd1bb4a1f6f80ee93c6b..0b5491d66aad03a77512c492f96b31f264b05da5 100644 --- a/en/application-dev/reference/apis/js-apis-volumemanager.md +++ b/en/application-dev/reference/apis/js-apis-volumemanager.md @@ -1,28 +1,27 @@ # Volume Management -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> -> The initial APIs of this module are supported since API version 8. 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> - This is a system API and cannot be called by third-party applications. ## Modules to Import ```js -import volumemanager from "@ohos.volumemanager"; +import volumemanager from "@ohos.volumeManager"; ``` -## System Capabilities +## volumemanager.getAllVolumes9+ -SystemCapability.FileManagement.StorageService.Volume - -## volumemanager.getAllVolumes - -getAllVolumes(): Promise<Volume[]> +getAllVolumes(): Promise<Array<Volume>> Asynchronously obtains information about all available volumes. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.StorageService.Volume + - Return value - | Type| Description| + | Type | Description | | ---------------------------------- | -------------------------- | | Promise<[Volume](#volume)[]> | Promise used to return the execution result.| @@ -34,17 +33,19 @@ Asynchronously obtains information about all available volumes. This method uses }); ``` -## volumemanager.getAllVolumes +## volumemanager.getAllVolumes9+ -getAllVolumes(callback:AsyncCallback<Volume[]>):void +getAllVolumes(callback: AsyncCallback<Array<Volume>>): void Asynchronously obtains information about all available volumes. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.StorageService.Volume + - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------- | ---- | ------------------------------------ | - | callback | callback:AsyncCallback<[Volume](#volume)[]> | Yes| Callback invoked to return the volume information obtained.| + | callback | callback:AsyncCallback<[Volume](#volume)[]> | Yes | Callback invoked to return the volume information obtained.| - Example @@ -56,21 +57,23 @@ Asynchronously obtains information about all available volumes. This method uses ``` -## volumemanager.mount +## volumemanager.mount9+ mount(volumeId: string): Promise<boolean> Asynchronously mounts a volume. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.StorageService.Volume + - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description| | -------- | ------ | ---- | ---- | - | volumeId | string | Yes| Volume ID.| + | volumeId | string | Yes | Volume ID.| - Return value - | Type| Description| + | Type | Description | | ---------------------- | ---------- | | Promise<boolean> | Promise used to return the execution result.| @@ -83,18 +86,20 @@ Asynchronously mounts a volume. This method uses a promise to return the result. }); ``` -## volumemanager.mount +## volumemanager.mount9+ mount(volumeId: string, callback:AsyncCallback<boolean>):void -Asynchronously mounts a volume. This method uses a callback to return the result. +Asynchronously obtains the available space of the specified volume. This method uses a callback to return the result. + +**System capability**: SystemCapability.FileManagement.StorageService.Volume - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | -------------------- | - | volumeId | string | Yes| Volume ID.| - | callback | callback:AsyncCallback<boolean> | Yes| Callback invoked to return the execution result.| + | volumeId | string | Yes | Volume ID. | + | callback | callback:AsyncCallback<boolean> | Yes | Callback invoked to return the execution result.| - Example @@ -105,21 +110,23 @@ Asynchronously mounts a volume. This method uses a callback to return the result }); ``` -## volumemanager.unmount +## volumemanager.unmount9+ unmount(volumeId: string): Promise<boolean> Asynchronously unmounts a volume. This method uses a promise to return the result. +**System capability**: SystemCapability.FileManagement.StorageService.Volume + - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description| | -------- | ------ | ---- | ---- | - | volumeId | string | Yes| Volume ID.| + | volumeId | string | Yes | Volume ID.| - Return value - | Type| Description| + | Type | Description | | ---------------------- | ---------- | | Promise<boolean> | Promise used to return the execution result.| @@ -132,18 +139,20 @@ Asynchronously unmounts a volume. This method uses a promise to return the resul }); ``` -## volumemanager.unmount +## volumemanager.unmount9+ unmount(volumeId: string, callback:AsyncCallback<boolean>):void Asynchronously unmounts a volume. This method uses a callback to return the result. +**System capability**: SystemCapability.FileManagement.StorageService.Volume + - Parameters - | Name| Type| Mandatory| Description| + | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | -------------------- | - | volumeId | string | Yes| Volume ID.| - | callback | callback:AsyncCallback<boolean> | Yes| Callback invoked to return the execution result.| + | volumeId | string | Yes | Volume ID. | + | callback | callback:AsyncCallback<boolean> | Yes | Callback invoked to return the execution result.| - Example @@ -154,15 +163,17 @@ Asynchronously unmounts a volume. This method uses a callback to return the resu }); ``` -## Volume +## Volume9+ + +**System capability**: SystemCapability.FileManagement.StorageService.Volume ### Attributes -| Name| Type| Description| +| Name | Type | Description | | ----------- | ------- | -------------------- | -| id | number | Volume ID.| -| uuid | string | Universally unique identifier (UUID) of the volume.| -| description | string | Description of the volume.| -| removeAble | boolean | Whether the volume is a removable storage device.| -| state | int | Current volume status.| -| path | string | Mount address of the volume.| +| id9+ | number | Volume ID. | +| uuid9+ | string | Universally unique identifier (UUID) of the volume. | +| description9+ | string | Description of the volume. | +| removable9+ | boolean | Whether the volume is a removable storage device.| +| state9+ | int | Current volume status. | +| path9+ | string | Mount address of the volume. |