未验证 提交 66ceaadb 编写于 作者: O openharmony_ci 提交者: Gitee

!5602 【翻译完成】#I5CCR5

Merge pull request !5602 from Annie_wang/PR5207
......@@ -3,7 +3,7 @@
> **NOTE**<br>
> 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.
This module provides file storage functions. It provides JS I/O APIs, including basic file management APIs, basic directory management APIs, statistical APIs for obtaining file information, and streaming APIs for reading and writing files.
Provides file storage and management capabilities, including basic file management, file directory management, file information statistics, and stream read and write.
## Modules to Import
......@@ -14,22 +14,14 @@ import fileio from '@ohos.fileio';
## Guidelines
Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Application sandbox path of a file or directory = Application directory + File name or directory name
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the application sandbox path of the file is as follows:
```js
let path = dir + "/xxx.txt";
```
The file descriptor is as follows:
```js
let fd = fileio.openSync(path);
Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the application sandbox as follows:
```js
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let path = '';
context.getFilesDir().then((data) => {
path = data;
})
```
......@@ -37,7 +29,7 @@ let fd = fileio.openSync(path);
stat(path: string): Promise&lt;Stat&gt;
Asynchronously obtains file information. This API uses a promise to return the result.
Obtains file information. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -45,7 +37,7 @@ Asynchronously obtains file information. This API uses a promise to return the r
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| path | string | Yes | Application sandbox path of the file.|
**Return value**
......@@ -56,7 +48,7 @@ Asynchronously obtains file information. This API uses a promise to return the r
**Example**
```js
fileio.stat(path).then(function(stat){
console.info("getFileInfo successfully:"+ JSON.stringify(stat));
console.info("Got file info successfully:"+ JSON.stringify(stat));
}).catch(function(err){
console.info("getFileInfo failed with error:"+ err);
});
......@@ -67,14 +59,14 @@ Asynchronously obtains file information. This API uses a promise to return the r
stat(path:string, callback:AsyncCallback&lt;Stat&gt;): void
Asynchronously obtains file information. This API uses a callback to return the result.
Obtains file information. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
**Example**
......@@ -96,7 +88,7 @@ Synchronously obtains file information.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| path | string | Yes | Application sandbox path of the file.|
**Return value**
......@@ -115,7 +107,7 @@ Synchronously obtains file information.
opendir(path: string): Promise&lt;Dir&gt;
Asynchronously opens a directory. This API uses a promise to return the result.
Opens a file directory. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -127,12 +119,12 @@ Asynchronously opens a directory. This API uses a promise to return the result.
**Return value**
| Type | Description |
| -------------------------- | -------- |
| Promise&lt;[Dir](#dir)&gt; | A **Dir** instance corresponding to the directory.|
| Promise&lt;[Dir](#dir)&gt; | Promise used to return the **Dir** object.|
**Example**
```js
fileio.opendir(path).then(function(dir){
console.info("opendir successfully:"+ JSON.stringify(dir));
console.info("Opened directory successfully:"+ JSON.stringify(dir));
}).catch(function(err){
console.info("opendir failed with error:"+ err);
});
......@@ -143,7 +135,7 @@ Asynchronously opens a directory. This API uses a promise to return the result.
opendir(path: string, callback: AsyncCallback&lt;Dir&gt;): void
Asynchronously opens a directory. This API uses a callback to return the result.
Opens a file directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -195,7 +187,7 @@ Synchronously opens a directory.
access(path: string, mode?: number): Promise&lt;void&gt;
Asynchronously checks whether the current process can access a file. This API uses a promise to return the result.
Checks whether the current process can access a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -203,18 +195,18 @@ Asynchronously checks whether the current process can access a file. This API us
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.access(path).then(function() {
console.info("access successfully");
console.info("access succeed");
}).catch(function(err){
console.info("access failed with error:"+ err);
});
......@@ -225,14 +217,14 @@ Asynchronously checks whether the current process can access a file. This API us
access(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously checks whether the current process can access a file. This API uses a callback to return the result.
Checks whether the current process can access a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously checked. |
......@@ -255,7 +247,7 @@ Synchronously checks whether the current process can access the specified file.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.|
**Example**
......@@ -272,7 +264,7 @@ Synchronously checks whether the current process can access the specified file.
close(fd: number):Promise&lt;void&gt;
Asynchronously closes a file. This API uses a promise to return the result.
Closes a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -284,13 +276,13 @@ Asynchronously closes a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
let fd = fileio.openSync(path);
fileio.close(fd).then(function(){
console.info("close file successfully");
console.info("close file succeed");
}).catch(function(err){
console.info("close file failed with error:"+ err);
});
......@@ -301,7 +293,7 @@ Asynchronously closes a file. This API uses a promise to return the result.
close(fd: number, callback:AsyncCallback&lt;void&gt;): void
Asynchronously closes a file. This API uses a callback to return the result.
Closes a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -343,19 +335,19 @@ Synchronously closes a file.
close(): Promise&lt;void&gt;
Asynchronously closes the stream. This API uses a promise to return the result.
Closes the stream. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.close().then(function(){
console.info("close file stream successfully");
console.info("close file stream succeed");
}).catch(function(err){
console.info("close file stream failed with error:"+ err);
});
......@@ -366,7 +358,7 @@ Asynchronously closes the stream. This API uses a promise to return the result.
close(callback: AsyncCallback&lt;void&gt;): void
Asynchronously closes the stream. This API uses a callback to return the result.
Closes the stream. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -387,7 +379,7 @@ Asynchronously closes the stream. This API uses a callback to return the result.
copyFile(src:string | number, dest:string | number, mode?:number):Promise&lt;void&gt;
Asynchronously copies a file. This API uses a promise to return the result.
Copies a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -401,12 +393,12 @@ Asynchronously copies a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.copyFile(src, dest).then(function(){
console.info("copyFile successfully");
console.info("copyFile succeed");
}).catch(function(err){
console.info("copyFile failed with error:"+ err);
});
......@@ -417,7 +409,7 @@ Asynchronously copies a file. This API uses a promise to return the result.
copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously copies a file. This API uses a callback to return the result.
Copies a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -462,25 +454,25 @@ Synchronously copies a file.
mkdir(path:string, mode?: number): Promise&lt;void&gt;
Asynchronously creates a directory. This API uses a promise to return the result.
Creates a directory. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory to create. |
| path | string | Yes | Application sandbox path of the directory. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.mkdir(path).then(function() {
console.info("mkdir successfully");
console.info("mkdir succeed");
}).catch(function (error){
console.info("mkdir failed with error:"+ error);
});
......@@ -491,21 +483,21 @@ Asynchronously creates a directory. This API uses a promise to return the result
mkdir(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously creates a directory. This API uses a callback to return the result.
Creates a directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory to create. |
| path | string | Yes | Application sandbox path of the directory. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. |
**Example**
```js
fileio.mkdir(path, function(err) {
console.info("mkdir successfully");
console.info("mkdir succeed");
});
```
......@@ -521,7 +513,7 @@ Synchronously creates a directory.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory to create. |
| path | string | Yes | Application sandbox path of the directory. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Example**
......@@ -534,26 +526,26 @@ Synchronously creates a directory.
open(path: string, flags?: number, mode?: number): Promise&lt;number&gt;
Asynchronously opens a file. This API uses a promise to return the result.
Opens a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**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 (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Return value**
| Type | Description |
| --------------------- | ----------- |
| Promise&lt;number&gt; | File descriptor of the file opened.|
| Promise&lt;number&gt; | Promise used to return the file descriptor of the file opened.|
**Example**
```js
fileio.open(path, 0o1, 0o0200).then(function(number){
console.info("open file successfully");
console.info("Opened file successfully");
}).catch(function(error){
console.info("open file failed with error:"+ err);
});
......@@ -564,14 +556,14 @@ Asynchronously opens a file. This API uses a promise to return the result.
open(path: string, flags: number, mode: number, callback: AsyncCallback&lt;number&gt;): void
Asynchronously opens a file. This API uses a callback to return the result.
Opens a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| 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.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**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 (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
| callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file is open asynchronously. |
......@@ -595,9 +587,9 @@ Synchronously opens a file.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**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 (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o640**: The owner has the read and write permissions, and the user group has the read permission.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.|
**Return value**
| Type | Description |
......@@ -606,7 +598,15 @@ Synchronously opens a file.
**Example**
```js
let fd = fileio.openSync(path);
let fd = fileio.openSync(path, 0o102, 0o640);
```
```js
let fd = fileio.openSync(path, 0o102, 0o666);
fileio.writeSync(fd, 'hello world');
let fd1 = fileio.openSync(path, 0o2002);
fileio.writeSync(fd1, 'hello world');
let num = fileio.readSync(fd1, new ArrayBuffer(4096), {position: 0});
console.info("num == " + num);
```
......@@ -618,7 +618,7 @@ read(fd: number, buffer: ArrayBuffer, options?: {
position?: number;
}): Promise&lt;ReadOut&gt;
Asynchronously reads data from a file. This API uses a promise to return the result.
Reads data from a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -633,14 +633,14 @@ Asynchronously reads data from a file. This API uses a promise to return the res
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.|
| Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example**
```js
let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096);
fileio.read(fd, buf).then(function(readout){
console.info("read file data successfully");
console.info("Read file data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(error){
console.info("read file data failed with error:"+ error);
......@@ -656,7 +656,7 @@ read(fd: number, buffer: ArrayBuffer, options: {
position?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void
Asynchronously reads data from a file. This API uses a callback to return the result.
Reads data from a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -674,7 +674,7 @@ Asynchronously reads data from a file. This API uses a callback to return the re
let buf = new ArrayBuffer(4096);
fileio.read(fd, buf, function (err, readOut) {
if (readOut) {
console.info("read file data successfully");
console.info("Read file data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}
});
......@@ -717,7 +717,7 @@ Synchronously reads data from a file.
rmdir(path: string): Promise&lt;void&gt;
Asynchronously deletes a directory. This API uses a promise to return the result.
Deletes a directory. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -729,12 +729,12 @@ Asynchronously deletes a directory. This API uses a promise to return the result
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.rmdir(path).then(function() {
console.info("rmdir successfully");
console.info("rmdir succeed");
}).catch(function(err){
console.info("rmdir failed with error:"+ err);
});
......@@ -745,7 +745,7 @@ Asynchronously deletes a directory. This API uses a promise to return the result
rmdir(path: string, callback:AsyncCallback&lt;void&gt;): void
Asynchronously deletes a directory. This API uses a callback to return the result.
Deletes a directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -759,7 +759,7 @@ Asynchronously deletes a directory. This API uses a callback to return the resul
```js
fileio.rmdir(path, function(err){
// Do something.
console.info("rmdir successfully");
console.info("rmdir succeed");
});
```
......@@ -787,7 +787,7 @@ Synchronously deletes a directory.
unlink(path:string): Promise&lt;void&gt;
Asynchronously deletes a file. This API uses a promise to return the result.
Deletes a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -799,12 +799,12 @@ Asynchronously deletes a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.unlink(path).then(function(){
console.info("remove file successfully");
console.info("Removed file successfully");
}).catch(function(error){
console.info("remove file failed with error:"+ error);
});
......@@ -815,20 +815,20 @@ Asynchronously deletes a file. This API uses a promise to return the result.
unlink(path:string, callback:AsyncCallback&lt;void&gt;): void
Asynchronously deletes a file. This API uses a callback to return the result.
Deletes a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file to delete.|
| path | string | Yes | Application sandbox path of the file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is deleted asynchronously. |
**Example**
```js
fileio.unlink(path, function(err) {
console.info("remove file successfully");
console.info("Removed file successfully");
});
```
......@@ -844,7 +844,7 @@ Synchronously deletes a file.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file to delete.|
| path | string | Yes | Application sandbox path of the file.|
**Example**
```js
......@@ -861,7 +861,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
encoding?: string;
}): Promise&lt;number&gt;
Asynchronously writes data into a file. This API uses a promise to return the result.
Writes data into a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -875,13 +875,13 @@ Asynchronously writes data into a file. This API uses a promise to return the re
**Return value**
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Length of the data written in the file.|
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Example**
```js
let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world").then(function(number){
console.info("write data to file successfully and size is:"+ number);
console.info("Wrote data to file successfully and size is:"+ number);
}).catch(function(err){
console.info("write data to file failed with error:"+ err);
});
......@@ -897,7 +897,7 @@ write(fd: number, buffer: ArrayBuffer | string, options: {
encoding?: string;
}, callback: AsyncCallback&lt;number&gt;): void
Asynchronously writes data into a file. This API uses a callback to return the result.
Writes data into a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -914,7 +914,7 @@ Asynchronously writes data into a file. This API uses a callback to return the r
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world", function (err, bytesWritten) {
if (bytesWritten) {
console.info("write data to file successfully and size is:"+ bytesWritten);
console.info("Wrote data to file successfully and size is:"+ bytesWritten);
}
});
```
......@@ -956,25 +956,25 @@ Synchronously writes data into a file.
hash(path: string, algorithm: string): Promise&lt;string&gt;
Asynchronously calculates the hash value of a file. This API uses a promise to return the result.
Calculates the hash value of a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.|
**Return value**
| Type | Description |
| --------------------- | -------------------------- |
| Promise&lt;string&gt; | Promise used to return the hash value of the file. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
| Promise&lt;string&gt; | Promise used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
**Example**
```js
fileio.hash(path, "sha256").then(function(str){
console.info("calculate file hash successfully:"+ str);
console.info("Calculated file hash successfully:"+ str);
}).catch(function(error){
console.info("calculate file hash failed with error:"+ err);
});
......@@ -985,22 +985,22 @@ Asynchronously calculates the hash value of a file. This API uses a promise to r
hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): void
Asynchronously calculates the hash value of a file. This API uses a callback to return the result.
Calculates the hash value of a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | --------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the hash value. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
**Example**
```js
fileio.hash(fpath, "sha256", function(err, hashStr) {
if (hashStr) {
console.info("calculate file hash successfully:"+ hashStr);
console.info("Calculated file hash successfully:"+ hashStr);
}
});
```
......@@ -1010,25 +1010,25 @@ Asynchronously calculates the hash value of a file. This API uses a callback to
chmod(path: string, mode: number):Promise&lt;void&gt;
Asynchronously changes the file permissions based on its path. This API uses a promise to return the result.
Changes file permissions. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.chmod(path, mode).then(function() {
console.info("chmod successfully");
console.info("chmod succeed");
}).catch(function(err){
console.info("chmod failed with error:"+ err);
});
......@@ -1039,14 +1039,14 @@ Asynchronously changes the file permissions based on its path. This API uses a p
chmod(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously changes the file permissions based on its path. This API uses a callback to return the result.
Changes file permissions. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
......@@ -1062,14 +1062,14 @@ Asynchronously changes the file permissions based on its path. This API uses a c
chmodSync(path: string, mode: number): void
Synchronously changes the file permissions based on its path.
Synchronously changes file permissions.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Example**
......@@ -1082,7 +1082,7 @@ Synchronously changes the file permissions based on its path.
fstat(fd: number): Promise&lt;Stat&gt;
Asynchronously obtains file information based on the file descriptor. This API uses a promise to return the result.
Obtains file information based on the file descriptor. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1094,12 +1094,12 @@ Asynchronously obtains file information based on the file descriptor. This API u
**Return value**
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information.|
**Example**
```js
fileio.fstat(fd).then(function(stat){
console.info("fstat successfully:"+ JSON.stringify(stat));
console.info("fstat succeed:"+ JSON.stringify(stat));
}).catch(function(err){
console.info("fstat failed with error:"+ err);
});
......@@ -1110,7 +1110,7 @@ Asynchronously obtains file information based on the file descriptor. This API u
fstat(fd: number, callback: AsyncCallback&lt;Stat&gt;): void
Asynchronously obtains file information based on the file descriptor. This API uses a callback to return the result.
Obtains file information based on the file descriptor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1158,7 +1158,7 @@ Synchronously obtains file information based on the file descriptor.
ftruncate(fd: number, len?: number): Promise&lt;void&gt;
Asynchronously truncates a file based on the file descriptor. This API uses a promise to return the result.
Truncates a file based on the file descriptor. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1166,18 +1166,18 @@ Asynchronously truncates a file based on the file descriptor. This API uses a pr
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
| len | number | No | File length, in bytes, after truncation.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
let fd = fileio.openSync(path);
fileio.ftruncate(fd, 5).then(function(err) {
console.info("File truncated successfully.");
console.info("truncate file succeed");
}).catch(function(err){
console.info("Failed to truncate the file. Error:"+ err);
});
......@@ -1188,7 +1188,7 @@ Asynchronously truncates a file based on the file descriptor. This API uses a pr
ftruncate(fd: number, len: number, callback:AsyncCallback&lt;void&gt;): void
Asynchronously truncates a file based on the file descriptor. This API uses a callback to return the result.
Truncates a file based on the file descriptor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1197,7 +1197,7 @@ Asynchronously truncates a file based on the file descriptor. This API uses a ca
| -------- | ------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is truncated asynchronously. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback which returns no value. |
**Example**
```js
......@@ -1231,7 +1231,7 @@ Synchronously truncates a file based on the file descriptor.
truncate(path: string, len?: number): Promise&lt;void&gt;
Asynchronously truncates a file based on its path. This API uses a promise to return the result.
Truncates a file based on the file path. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1239,17 +1239,17 @@ Asynchronously truncates a file based on its path. This API uses a promise to re
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
| len | number | No | File length, in bytes, after truncation.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.truncate(path, len).then(function(){
console.info("File truncated successfully.");
console.info("Truncated file successfully");
}).catch(function(err){
console.info("Failed to truncate the file. Error:"+ err);
});
......@@ -1260,7 +1260,7 @@ Asynchronously truncates a file based on its path. This API uses a promise to re
truncate(path: string, len: number, callback:AsyncCallback&lt;void&gt;): void
Asynchronously truncates a file based on its path. This API uses a callback to return the result.
Truncates a file based on the file path. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1269,7 +1269,7 @@ Asynchronously truncates a file based on its path. This API uses a callback to r
| -------- | ------------------------- | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is truncated asynchronously. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback which returns no value. |
**Example**
```js
......@@ -1290,7 +1290,7 @@ Synchronously truncates a file based on the file path.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to be truncate. |
| path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.|
**Example**
......@@ -1307,7 +1307,7 @@ readText(filePath: string, options?: {
encoding?: string;
}): Promise&lt;string&gt;
Asynchronously reads the text of a file. This API uses a promise to return the result.
Reads the text content of a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1320,12 +1320,12 @@ Asynchronously reads the text of a file. This API uses a promise to return the r
**Return value**
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content of the file read.|
| Promise&lt;string&gt; | Promise used to return the content read.|
**Example**
```js
fileio.readText(path).then(function(str) {
console.info("readText successfully:"+ str);
console.info("Read text successfully:"+ str);
}).catch(function(err){
console.info("readText failed with error:"+ err);
});
......@@ -1340,7 +1340,7 @@ readText(filePath: string, options: {
encoding?: string;
}, callback: AsyncCallback&lt;string&gt;): void
Asynchronously reads the text of a file. This API uses a callback to return the result.
Reads the text content of a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1348,8 +1348,8 @@ Asynchronously reads the text of a file. This API uses a callback to return the
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when the file is read asynchronously. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- &nbsp;**encoding**: format of the string to be encoded. The default value is &nbsp;**utf-8**, which is the only value supported.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the content read. |
**Example**
```js
......@@ -1392,7 +1392,7 @@ Synchronously reads the text of a file.
lstat(path: string): Promise&lt;Stat&gt;
Asynchronously obtains link information. This API uses a promise to return the result.
Obtains link information. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1404,12 +1404,12 @@ Asynchronously obtains link information. This API uses a promise to return the r
**Return value**
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the link information obtained.|
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the link information obtained. For details, see [Stat](#stat).|
**Example**
```js
fileio.lstat(path).then(function(stat){
console.info("Link status obtained:"+ number);
console.info("Got link info successfully:"+ number);
}).catch(function(err){
console.info("Failed to obtain the link status. Error:"+ err);
});
......@@ -1420,7 +1420,7 @@ Asynchronously obtains link information. This API uses a promise to return the r
lstat(path:string, callback:AsyncCallback&lt;Stat&gt;): void
Asynchronously obtains link information. This API uses a callback to return the result.
Obtains link information. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1428,7 +1428,7 @@ Asynchronously obtains link information. This API uses a callback to return the
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file, pointing to the link.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the link information obtained. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback used to return the link information obtained. |
**Example**
```js
......@@ -1449,7 +1449,7 @@ Synchronously obtains the link information.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file, pointing to the link.|
| path | string | Yes | Application sandbox path of the target file.|
**Return value**
| Type | Description |
......@@ -1470,7 +1470,7 @@ read(buffer: ArrayBuffer, options?: {
length?: number;
}): Promise&lt;ReadOut&gt;
Asynchronously reads data from a file. This API uses a promise to return the result.
Reads data from a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1483,12 +1483,12 @@ Asynchronously reads data from a file. This API uses a promise to return the res
**Return value**
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.|
| Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example**
```js
fileio.read(new ArrayBuffer(4096)).then(function(readout){
console.info("read file data successfully");
console.info("Read file data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){
console.info("Failed to read file data. Error:"+ err);
......@@ -1504,7 +1504,7 @@ read(buffer: ArrayBuffer, options: {
length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void
Asynchronously reads data from a file. This API uses a callback to return the result.
Reads data from a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1520,7 +1520,7 @@ Asynchronously reads data from a file. This API uses a callback to return the re
let buf = new ArrayBuffer(4096);
fileio.read(buf, function (err, readOut) {
if (readOut) {
console.info("read file data successfully");
console.info("Read file data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}
});
......@@ -1531,7 +1531,7 @@ Asynchronously reads data from a file. This API uses a callback to return the re
rename(oldPath: string, newPath: string): Promise&lt;void&gt;
Asynchronously renames a file. This API uses a promise to return the result.
Renames a file. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1544,12 +1544,12 @@ Asynchronously renames a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.rename(oldPath, newPath).then(function() {
console.info("rename successfully");
console.info("rename succeed");
}).catch(function(err){
console.info("rename failed with error:"+ err);
});
......@@ -1560,7 +1560,7 @@ Asynchronously renames a file. This API uses a promise to return the result.
rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously renames a file. This API uses a callback to return the result.
Renames a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1568,7 +1568,7 @@ Asynchronously renames a file. This API uses a callback to return the result.
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------- |
| oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Application sandbox path of the file renamed. |
| newPath | String | Yes | Application sandbox path of the file renamed. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously renamed. |
**Example**
......@@ -1602,19 +1602,19 @@ Synchronously renames a file.
fsync(fd: number): Promise&lt;void&gt;
Asynchronously synchronizes a file. This API uses a promise to return the result.
Flushes data of a file to disk. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.|
| fd | number | Yes | File descriptor of the file to flush.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
......@@ -1630,14 +1630,14 @@ Asynchronously synchronizes a file. This API uses a promise to return the result
fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously synchronizes a file. This API uses a callback to return the result.
Flushes data of a file to disk. This API uses an asynchronous 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 synchronize. |
| fd | number | Yes | File descriptor of the file to flush. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is synchronized in asynchronous mode.|
**Example**
......@@ -1652,14 +1652,14 @@ Asynchronously synchronizes a file. This API uses a callback to return the resul
fsyncSync(fd: number): void
Synchronizes a file in synchronous mode.
Flushes data of a file to disk in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.|
| fd | number | Yes | File descriptor of the file to flush.|
**Example**
```js
......@@ -1671,24 +1671,24 @@ Synchronizes a file in synchronous mode.
fdatasync(fd: number): Promise&lt;void&gt;
Asynchronously synchronizes data in a file. This API uses a promise to return the result.
Flushes data of a file to disk. This API uses a promise to return the result asynchronously. **fdatasync()** is similar to **fsync()**, but does not flush modified metadata unless that metadata is needed.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.|
| fd | number | Yes | File descriptor of the file to flush.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.fdatasync(fd).then(function(err) {
console.info("sync data successfully");
console.info("sync data succeed");
}).catch(function(err){
console.info("sync data failed with error:"+ err);
});
......@@ -1699,7 +1699,7 @@ Asynchronously synchronizes data in a file. This API uses a promise to return th
fdatasync(fd: number, callback:AsyncCallback&lt;void&gt;): void
Asynchronously synchronizes data in a file. This API uses a callback to return the result.
Flushes data of a file to disk. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1728,7 +1728,7 @@ Synchronizes data in a file in synchronous mode.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.|
| fd | number | Yes | File descriptor of the file to flush.|
**Example**
```js
......@@ -1740,25 +1740,25 @@ Synchronizes data in a file in synchronous mode.
symlink(target: string, srcPath: string): Promise&lt;void&gt;
Asynchronously creates a symbolic link based on a path. This API uses a promise to return the result.
Creates a symbolic link based on a path. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Application sandbox path of the symbolic link. |
| srcPath | string | Yes | Application sandbox path of the referenced file or directory contained in the symbolic link.|
| target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Application sandbox path of the symbolic link file.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.symlink(target, srcPath).then(function() {
console.info("symlink successfully");
console.info("symlink succeed");
}).catch(function(err){
console.info("symlink failed with error:"+ err);
});
......@@ -1769,15 +1769,15 @@ Asynchronously creates a symbolic link based on a path. This API uses a promise
symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously creates a symbolic link based on a path. This API uses a callback to return the result.
Creates a symbolic link based on a path. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------- |
| target | string | Yes | Application sandbox path of the symbolic link. |
| srcPath | string | Yes | Application sandbox path of the referenced file or directory contained in the symbolic link. |
| target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Application sandbox path of the symbolic link file. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the symbolic link is created asynchronously.|
**Example**
......@@ -1799,8 +1799,8 @@ Synchronously creates a symbolic link based on a specified path.
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Application sandbox path of the symbolic link. |
| srcPath | string | Yes | Application sandbox path the referenced file or directory contained in the symbolic link.|
| target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Application sandbox path of the symbolic link file.|
**Example**
```js
......@@ -1812,27 +1812,27 @@ Synchronously creates a symbolic link based on a specified path.
chown(path: string, uid: number, gid: number): Promise&lt;void&gt;
Asynchronously changes the file owner based on its path. This API uses a promise to return the result.
Changes the file owner based on the file path. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| path | string | Yes | Application sandbox path of the file.|
| uid | number | Yes | New user ID (UID). |
| gid | number | Yes | New group ID (GID). |
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
let stat = fileio.statSync(path);
fileio.chown(path, stat.uid, stat.gid).then(function(){
console.info("chown successfully");
console.info("chown succeed");
}).catch(function(err){
console.info("chown failed with error:"+ err);
});
......@@ -1843,14 +1843,14 @@ Asynchronously changes the file owner based on its path. This API uses a promise
chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously changes the file owner based on its path. This API uses a callback to return the result.
Changes the file owner based on the file path. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
......@@ -1875,7 +1875,7 @@ Synchronously changes the file owner based on its path.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| path | string | Yes | Application sandbox path of the file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
......@@ -1890,7 +1890,7 @@ Synchronously changes the file owner based on its path.
mkdtemp(prefix: string): Promise&lt;string&gt;
Asynchronously creates a temporary directory. This API uses a promise to return the result.
Creates a temporary directory. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1902,12 +1902,12 @@ Asynchronously creates a temporary directory. This API uses a promise to return
**Return value**
| Name | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Unique path generated.|
| Promise&lt;string&gt; | Promise used to return the directory generated.|
**Example**
```js
fileio.mkdtemp(path + "XXXX").then(function(path){
console.info("mkdtemp successfully:"+ path);
console.info("mkdtemp succeed:"+ path);
}).catch(function(err){
console.info("mkdtemp failed with error:"+ err);
});
......@@ -1918,7 +1918,7 @@ Asynchronously creates a temporary directory. This API uses a promise to return
mkdtemp(prefix: string, callback: AsyncCallback&lt;string&gt;): void
Asynchronously creates a temporary directory. This API uses a callback to return the result.
Creates a temporary directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1964,7 +1964,7 @@ Synchronously creates a temporary directory.
fchmod(fd: number, mode: number): Promise&lt;void&gt;
Asynchronously changes the file permissions based on the file descriptor. This API uses a promise to return the result.
Changes file permissions based on the file descriptor. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1977,12 +1977,12 @@ Asynchronously changes the file permissions based on the file descriptor. This A
**Return value**
| Name | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
fileio.fchmod(fd, mode).then(function() {
console.info("chmod successfully");
console.info("chmod succeed");
}).catch(function(err){
console.info("chmod failed with error:"+ err);
});
......@@ -1993,7 +1993,7 @@ Asynchronously changes the file permissions based on the file descriptor. This A
fchmod(fd: number, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously changes the file permissions based on the file descriptor. This API uses a callback to return the result.
Changes file permissions based on the file descriptor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2036,14 +2036,14 @@ Synchronously changes the file permissions based on the file descriptor.
createStream(path: string, mode: string): Promise&lt;Stream&gt;
Asynchronously opens a stream based on the file path. This API uses a promise to return the result.
Opens a file stream based on the file path. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**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**
......@@ -2054,7 +2054,7 @@ Asynchronously opens a stream based on the file path. This API uses a promise to
**Example**
```js
fileio.createStream(path, "r+").then(function(stream){
console.info("createStream successfully");
console.info("createStream succeed");
}).catch(function(err){
console.info("createStream failed with error:"+ err);
});
......@@ -2065,14 +2065,14 @@ Asynchronously opens a stream based on the file path. This API uses a promise to
createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
Asynchronously opens a stream based on the file path. This API uses a callback to return the result.
Opens a stream based on the file path. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**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&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
......@@ -2095,7 +2095,7 @@ Synchronously opens a stream based on the file path.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**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**
......@@ -2113,7 +2113,7 @@ Synchronously opens a stream based on the file path.
fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;
Asynchronously opens a stream based on the file descriptor. This API uses a promise to return the result.
Opens a file stream based on the file descriptor. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2131,7 +2131,7 @@ Asynchronously opens a stream based on the file descriptor. This API uses a prom
**Example**
```js
fileio.fdopenStream(fd, mode).then(function(stream){
console.info("openStream successfully");
console.info("openStream succeed");
}).catch(function(err){
console.info("openStream failed with error:"+ err);
});
......@@ -2142,7 +2142,7 @@ Asynchronously opens a stream based on the file descriptor. This API uses a prom
fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
Asynchronously opens a stream based on the file descriptor. This API uses a callback to return the result.
Opens a file stream based on the file descriptor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2190,7 +2190,7 @@ Synchronously opens a stream based on the file descriptor.
fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt;
Asynchronously changes the file owner based on the file descriptor. This API uses a promise to return the result.
Changes the file owner based on the file descriptor. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2204,13 +2204,13 @@ Asynchronously changes the file owner based on the file descriptor. This API use
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid).then(function() {
console.info("chown successfully");
console.info("chown succeed");
}).catch(function(err){
console.info("chown failed with error:"+ err);
});
......@@ -2221,7 +2221,7 @@ Asynchronously changes the file owner based on the file descriptor. This API use
fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously changes the file owner based on the file descriptor. This API uses a callback to return the result.
Changes the file owner based on the file descriptor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2268,27 +2268,27 @@ Synchronously changes the file owner based on the file descriptor.
lchown(path: string, uid: number, gid: number): Promise&lt;void&gt;
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.
Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on the file path. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| path | string | Yes | Application sandbox path of the file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
| Promise&lt;void&gt; | Promise which returns no value.|
**Example**
```js
let stat = fileio.statSync(path);
fileio.lchown(path, stat.uid, stat.gid).then(function() {
console.info("chown successfully");
console.info("chown succeed");
}).catch(function(err){
console.info("chown failed with error:"+ err);
});
......@@ -2299,14 +2299,14 @@ Asynchronously changes the file owner based on the file path, changes the owner
lchown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): 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 callback.
Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on the file path. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| path | string | Yes | Application sandbox path of the file. |
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
......@@ -2331,7 +2331,7 @@ Synchronously changes the file owner based on the file path and changes the owne
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| path | string | Yes | Application sandbox path of the file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
......@@ -2346,21 +2346,21 @@ Synchronously changes the file owner based on the file path and changes the owne
createWatcher(filename: string, events: number, callback: AsyncCallback&lt;number&gt;): Watcher
Asynchronously listens for the changes of a file or directory. This API uses a callback to return the result.
Listens for file or directory changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
| filename | string | Yes | Application sandbox path of the target file. |
| filename | string | Yes | Application sandbox path of the file. |
| events | Number | Yes | -&nbsp;**1**: The file or directory is renamed.<br>-&nbsp;**2**: The file or directory is modified.<br>-&nbsp;**3**: The file or directory is modified and renamed.|
| callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. |
**Return value**
| Name | Description |
| -------------------- | ---------- |
| [Watcher](#watcher7) | Instance for listening for a file change event.|
| [Watcher](#watcher7) | Promise used to return the **Watcher** instance.|
**Example**
```js
......@@ -2549,7 +2549,7 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy
stop(): Promise&lt;void&gt;
Asynchronously stops **watcher**. This API uses a promise to return the result.
Stops the **watcher** instance. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2563,7 +2563,7 @@ Asynchronously stops **watcher**. This API uses a promise to return the result.
stop(callback: AsyncCallback&lt;void&gt;): void
Asynchronously stops **watcher**. This API uses a callback to return the result.
Stops the **watcher** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2583,14 +2583,14 @@ Asynchronously stops **watcher**. This API uses a callback to return the result.
## Stream<sup>7+</sup>
File stream. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance.
Provides file stream management. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance.
### close<sup>7+</sup>
close(): Promise&lt;void&gt;
Asynchronously closes the stream. This API uses a promise to return the result.
Closes the stream. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2603,7 +2603,7 @@ Asynchronously closes the stream. This API uses a promise to return the result.
```js
let ss= fileio.createStreamSync(path);
ss.close().then(function(){
console.info("close fileStream successfully");
console.info("Closed fileStream successfully");
}).catch(function(err){
console.info("close fileStream failed with error:"+ err);
});
......@@ -2614,7 +2614,7 @@ Asynchronously closes the stream. This API uses a promise to return the result.
close(callback: AsyncCallback&lt;void&gt;): void
Asynchronously closes the stream. This API uses a callback to return the result.
Closes the stream. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2627,7 +2627,7 @@ Asynchronously closes the stream. This API uses a callback to return the result.
```js
let ss= fileio.createStreamSync(path);
ss.close(function (err) {
// do something
// Do something
});
```
......@@ -2651,7 +2651,7 @@ Synchronously closes the stream.
flush(): Promise&lt;void&gt;
Asynchronously flushes the stream. This API uses a promise to return the result.
Flushes the stream. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2664,7 +2664,7 @@ Asynchronously flushes the stream. This API uses a promise to return the result.
```js
let ss= fileio.createStreamSync(path);
ss.flush().then(function (){
console.info("flush successfully");
console.info("Flushed stream successfully");
}).catch(function(err){
console.info("flush failed with error:"+ err);
});
......@@ -2675,7 +2675,7 @@ Asynchronously flushes the stream. This API uses a promise to return the result.
flush(callback: AsyncCallback&lt;void&gt;): void
Asynchronously flushes the stream. This API uses a callback to return the result.
Flushes the stream. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2688,7 +2688,7 @@ Asynchronously flushes the stream. This API uses a callback to return the result
```js
let ss= fileio.createStreamSync(path);
ss.flush(function (err) {
// do something
// Do something
});
```
......@@ -2717,7 +2717,7 @@ write(buffer: ArrayBuffer | string, options?: {
encoding?: string;
}): Promise&lt;number&gt;
Asynchronously writes data into the stream. This API uses a promise to return the result.
Writes data into the stream. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2730,13 +2730,13 @@ Asynchronously writes data into the stream. This API uses a promise to return th
**Return value**
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Length of the data written in the file.|
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
**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 and size is:"+ number);
console.info("Wrote data successfully and size is:"+ number);
}).catch(function(err){
console.info("write failed with error:"+ err);
});
......@@ -2752,7 +2752,7 @@ write(buffer: ArrayBuffer | string, options: {
encoding?: string;
}, callback: AsyncCallback&lt;number&gt;): void
Asynchronously writes data into the stream. This API uses a callback to return the result.
Writes data into the stream. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2768,8 +2768,8 @@ Asynchronously writes data into the stream. This API uses a callback to return t
let ss= fileio.createStreamSync(fpath, "r+");
ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) {
if (bytesWritten) {
// do something
console.info("write successfully and size is:"+ bytesWritten);
// Do something
console.info("Wrote data successfully and size is:"+ bytesWritten);
}
});
```
......@@ -2814,7 +2814,7 @@ read(buffer: ArrayBuffer, options?: {
length?: number;
}): Promise&lt;ReadOut&gt;
Asynchronously reads data from the stream. This API uses a promise to return the result.
Reads data from the stream. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2827,13 +2827,13 @@ Asynchronously reads data from the stream. This API uses a promise to return the
**Return value**
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.|
| Promise&lt;[ReadOut](#readout)&gt; | 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");
console.info("Read data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){
console.info("read data failed with error:"+ err);
......@@ -2849,7 +2849,7 @@ read(buffer: ArrayBuffer, options: {
length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void
Asynchronously reads data from the stream. This API uses a callback to return the result.
Reads data from the stream. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2865,7 +2865,7 @@ Asynchronously reads data from the stream. This API uses a callback to return th
let ss = fileio.createStreamSync(fpath, "r+");
ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
if (readOut) {
console.info("read data successfully");
console.info("Read data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}
});
......@@ -2913,20 +2913,20 @@ Manages directories. Before calling a method of the **Dir** class, use the [open
read(): Promise&lt;Dirent&gt;
Asynchronously reads the next directory entry. This API uses a promise to return the result.
Reads the next directory entry. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Return value**
| Type | Description |
| -------------------------------- | ------------- |
| Promise&lt;[Dirent](#dirent)&gt; | Directory entry that is read asynchronously.|
| Promise&lt;[Dirent](#dirent)&gt; | Promise used to return the directory entry read.|
**Example**
```js
let dir = fileio.opendirSync(path);
dir.read().then(function (dirent){
console.log("read successfully:"+JSON.stringify(dirent));
console.log("read succeed:"+JSON.stringify(dirent));
}).catch(function(err){
console.info("read failed with error:"+ err);
});
......@@ -2937,7 +2937,7 @@ Asynchronously reads the next directory entry. This API uses a promise to return
read(callback: AsyncCallback&lt;Dirent&gt;): void
Asynchronously reads the next directory entry. This API uses a callback to return the result.
Reads the next directory entry. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -2951,8 +2951,8 @@ Asynchronously reads the next directory entry. This API uses a callback to retur
let dir = fileio.opendirSync(path);
dir.read(function (err, dirent) {
if (dirent) {
// do something
console.log("read successfully:"+JSON.stringify(dirent));
// Do something
console.log("read succeed:"+JSON.stringify(dirent));
}
});
```
......@@ -2978,6 +2978,40 @@ Synchronously reads the next directory entry.
```
### close
close(): Promise&lt;void&gt;
Closes a directory. This API uses a promise to return the result asynchronously. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Example**
```js
let dir = fileio.opendirSync(path);
dir.close().then(function(err){
console.info("close dir successfully");
});
```
### close
close(callback: AsyncCallback&lt;void&gt;): void
Closes a directory. This API uses an asynchronous callback to return the result. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Example**
```js
let dir = fileio.opendirSync(path);
dir.close(function(err){
console.info("close dir successfully");
});
```
### closeSync
closeSync(): void
......@@ -3010,7 +3044,7 @@ Provides information about files and directories. Before calling a method of the
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.
Checks whether this 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
......@@ -3070,7 +3104,7 @@ Checks whether a directory entry is a directory.
isFIFO(): boolean
Checks whether the current directory entry is a named pipe (or FIFO). Named pipes are used for inter-process communication.
Checks whether this directory entry is a named pipe (or FIFO). Named pipes are used for inter-process communication.
**System capability**: SystemCapability.FileManagement.File.FileIO
......
......@@ -63,13 +63,19 @@ Obtains information about the root album or directory in asynchronous mode. This
- Example
```js
filemanager.getRoot((err, fileInfo) => {
let option = {
"dev":{
name:"",
}
};
filemanager.getRoot(option,(err, fileInfo)=>{
if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo));
}
}
}
});
```
## filemanager.listFile
......@@ -105,7 +111,7 @@ Obtains information about the second-level album or files in asynchronous mode.
```js
// Obtain all files in the directory.
// Call listFile() and getRoot() to obtain the file URI.
let media_path = file.uri
let media_path = file.path
filemanager.listFile(media_path, "file")
.then((fileInfo) => {
if(Array.isArray(fileInfo)) {
......@@ -114,10 +120,13 @@ Obtains information about the second-level album or files in asynchronous mode.
}
}
}).catch((err) => {
console.log(err)
});
console.log(err)
});
```
## filemanager.listFile
listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : number, count? : number}, callback : AsyncCallback&lt;FileInfo[]&gt;) : void
......@@ -130,8 +139,8 @@ Obtains information about the second-level album or files in asynchronous mode.
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | URI of the directory to query. |
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| path | string | Yes | URI of the directory to query. |
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
- Error
......@@ -145,14 +154,30 @@ Obtains information about the second-level album or files in asynchronous mode.
- Example
```js
// Call listFile() and getRoot() to obtain the file URI.
let media_path = file.uri
filemanager.listFile(media_path, "file", (err, fileInfo) => {
if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo));
}
}
// Call listFile() and getRoot() to obtain the file path.
let fileInfos = await filemanager.getRoot();
let media_path = "";
for (let i = 0; i < fileInfos.length; i++) {
if (fileInfos[i].name == "image_album") {
media_path = fileInfos[i].path;
} else if (fileInfos[i].name == "audio_album") {
media_path = fileInfos[i].path;
} else if (fileInfos[i].name == "video_album") {
media_path = fileInfos[i].path;
} else if (fileInfos[i].name == "file_folder") {
media_path = fileInfos[i].path;
}
}
filemanager.listFile(media_path, "file")
.then((fileInfo) => {
if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo));
}
}
}).catch((err) => {
console.log(err)
});
```
......@@ -211,8 +236,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- |
| filename | string | Yes | Name of the file to create. |
| path | string | Yes | URI of the file to create. |
| filename | string | Yes | Name of the file to create. |
| path | string | Yes | URI of the file to create. |
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
......@@ -230,7 +255,7 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb
```js
// Create a file.
// Call listFile() and getRoot() to obtain the file URI.
let media_path = file.uri
let media_path = file.path
// File to be saved.
let name = "xxx.jpg"
filemanager.createFile(media_path, name, (err, uri) => {
......
# statfs
> **NOTE**<br>
> **NOTE:**<br>
> 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 module provides information related to the file system. It provides JS APIs to obtain the total number of bytes and the number of idle bytes of the file system.
Obtains file system information, including the total number of bytes and the number of idle bytes of the file system.
## Modules to Import
```js
import statfs from '@ohos.statfs';
```
## Guidelines
Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Application sandbox path of a file or directory = Application directory + File name or directory name
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the application sandbox path of the file is as follows:
```js
let path = dir + "xxx.txt";
```
## statfs.getFreeBytes
getFreeBytes(path:string):Promise&lt;number&gt;
......@@ -72,8 +59,12 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
- Example
```js
statfs.getFreeBytes(path, function(err, number){
console.info("getFreeBytes callback successfully:"+ number);
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
context.getFilesDir().then(function (path) {
statfs.getFreeBytes(path, function(err, number){
console.info("getFreeBytes callback successfully:"+ number);
});
});
```
......@@ -126,7 +117,11 @@ Obtains the total number of bytes of the specified file system in asynchronous m
- Example
```js
statfs.getTotalBytes(path, function(err, number){
console.info("getTotalBytes callback successfully:"+ number);
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
context.getFilesDir().then(function (path) {
statfs.getTotalBytes(path, function(err, number){
console.info("getTotalBytes callback successfully:"+ number);
});
});
```
......@@ -25,11 +25,11 @@ Encrypts or decrypts data using RSA.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| action | string | Yes| Action to perform. The options are as follows:<br>-&nbsp;encrypt<br>-&nbsp;decrypt|
| text | string | Yes| Text to be encrypted or decrypted.<br> The text to be encrypted must be common text that meets the following requirement:<br> Maximum text length = Key length/8 - 66<br>For example, if the key is of 1024 bytes, the text to be encrypted cannot exceed 62 bytes (1024/8 -66 = 62).<br> The text to be decrypted must be binary text encoded in Base64. The default format is used for Base64 encoding.|
| action | string | Yes| Action to perform. The options are as follows:<br>-&nbsp;encrypt<br/>-&nbsp;decrypt|
| text | string | Yes| Text to be encrypted or decrypted.<br> The text to be encrypted must be common text that meets the following requirement:<br> Maximum text length = Key length/8 - 66<br>For example, if the key is of 1024 bytes, the text to be encrypted cannot exceed 62 bytes (1024/8 -66 = 62).<br> The text to be decrypted must be binary text encoded in Base64. The default format is used for Base64 encoding.|
| key | string | Yes| RSA key. The key is used as a public key in encryption and a private key in decryption.|
| transformation | string | No| RSA padding. The default value is **RSA/None/OAEPWithSHA256AndMGF1Padding**.|
| success | Function | No| Called when data is encrypted or decrypted successful.|
| success | Function | No| Called when data is encrypted or decrypted successfully.|
| fail | Function | No| Called when data fails to be encrypted or decrypted.|
| complete | Function | No| Called when the execution is complete.|
......@@ -104,14 +104,14 @@ Encrypts or decrypts data using AES.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| action | string | Yes| Action to perform. The options are as follows:<br>-&nbsp;encrypt<br>-&nbsp;decrypt|
| text | string | Yes| Text to be encrypted or decrypted.<br> The text to be encrypted must be common text. The text to be decrypted must be binary text encoded in Base64. The default format is used for Base64 encoding.|
| action | string | Yes| Action to perform. The options are as follows:<br>-&nbsp;encrypt<br/>-&nbsp;decrypt|
| text | string | Yes| Text to be encrypted or decrypted.<br> The text to be encrypted must be common text. The text to be decrypted must be binary text encoded in Base64. The default format is used for Base64 encoding.|
| key | string | Yes| Key used for encryption or decryption. It is a string encoded in Base64.|
| transformation | string | No| Encryption mode and padding of the AES algorithm. The default value is **AES/CBC/PKCS5Padding**.|
| iv | string | No| Initialization vector (IV) for AES-based encryption and decryption. The value is a string encoded in Base64. The default value is the key value.|
| ivOffset | string | No| Offset of the IV for AES-based encryption and decryption. The default value is **0**.|
| ivLen | string | No| Length of the IV for AES-based encryption and decryption, in bytes. The default value is **16**.|
| success | Function | No| Called when data is encrypted or decrypted successful.|
| success | Function | No| Called when data is encrypted or decrypted successfully.|
| fail | Function | No| Called when data fails to be encrypted or decrypted.|
| complete | Function | No| Called when the execution is complete.|
......
# File Storage
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.fileio`](js-apis-fileio.md) instead.
> **NOTE**<br/>
> - The APIs of this module are no longer maintained since API version 6. You are advised to use [`@ohos.fileio`](js-apis-fileio.md) instead.
>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......@@ -26,21 +24,21 @@ Moves a specified file to a given location.
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| srcUri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;file&nbsp;to&nbsp;move. |
| dstUri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;location&nbsp;to&nbsp;which&nbsp;the&nbsp;file&nbsp;is&nbsp;to&nbsp;move. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;source&nbsp;file&nbsp;is&nbsp;moved&nbsp;to&nbsp;the&nbsp;specified&nbsp;location&nbsp;successfully.&nbsp;This&nbsp;function&nbsp;returns&nbsp;the&nbsp;URI&nbsp;of&nbsp;the&nbsp;destination&nbsp;location. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| srcUri | string | Yes| Uniform resource identifier (URI) of the file to move. <br/>The URI can contain a maximum of 128 characters, excluding the following characters: "\*+,:;&lt;=&gt;?[]\|\x7F |
| dstUri | string | Yes| URI of the location to which the file is to move. <br/>The URI can contain a maximum of 128 characters, excluding the following characters: "\*+,:;&lt;=&gt;?[]\|\x7F |
| success | Function | No| Called when the file is moved to the specified location. This API returns the URI of the destination location.|
| fail | Function | No| Called when the file fails to be moved.|
| complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
| 301 | The file or directory does not exist.|
**Example**
......@@ -66,27 +64,27 @@ export default {
copy(Object): void
Copies a file and saves the copy to a specified location.
Copies a file to the given URI.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| srcUri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;file&nbsp;to&nbsp;copy. |
| dstUri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;location&nbsp;to&nbsp;which&nbsp;the&nbsp;copy&nbsp;is&nbsp;to&nbsp;save.<br>The&nbsp;directory&nbsp;of&nbsp;application&nbsp;resources&nbsp;and&nbsp;URI&nbsp;of&nbsp;the&nbsp;**tmp**&nbsp;type&nbsp;are&nbsp;not&nbsp;supported. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;source&nbsp;file&nbsp;is&nbsp;copied&nbsp;and&nbsp;saved&nbsp;to&nbsp;the&nbsp;specified&nbsp;location&nbsp;successfully.&nbsp;This&nbsp;function&nbsp;returns&nbsp;the&nbsp;URI&nbsp;of&nbsp;the&nbsp;destination&nbsp;location. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| srcUri | string | Yes| URI of the file to copy.|
| dstUri | string | Yes| URI of the location to which the copy is to be saved.<br>The directory of application resources and URI of the **tmp** type are not supported.|
| success | Function | No| Called when the file is copied and saved to the specified location. This API returns the URI of the destination location.|
| fail | Function | No| Called when the file fails to be copied.|
| complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
| 301 | The file or directory does not exist.|
**Example**
......@@ -112,41 +110,41 @@ export default {
list(Object): void
Obtains the list of all files in a specified directory.
Obtains all files in the specified directory.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;directory. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of the directory. <br/>The URI can contain a maximum of 128 characters, excluding the following characters: "\*+,:;&lt;=&gt;?[]\|\x7F |
| success | Function | No| Called when the file list is obtained.|
| fail | Function | No| Called when the file list fails to be obtained.|
| complete | Function | No| Called when the execution is complete.|
Return values of the **success** callback
Return values of the **success** callback:
| Name | Type | Description |
| Name| Type| Description|
| -------- | -------- | -------- |
| fileList | Array&lt;FileInfo&gt; | File&nbsp;list.&nbsp;The&nbsp;format&nbsp;of&nbsp;each&nbsp;file&nbsp;is&nbsp;as&nbsp;follows:<br/>{<br/>uri:'file1',<br/>lastModifiedTime:1589965924479,<br/>length:10240,<br/>type:&nbsp;'file'<br/>} |
| fileList | Array&lt;FileInfo&gt; | File list. The format of each file is as follows:<br>{<br>uri:'file1',<br>lastModifiedTime:1589965924479,<br>length:10240,<br>type:&nbsp;'file'<br>} |
**Table1** FileInfo
**Table 1** FileInfo
| Name | Type | Description |
| Name| Type| Description|
| -------- | -------- | -------- |
| uri | string | File&nbsp;URI. |
| lastModifiedTime | number | Timestamp&nbsp;when&nbsp;the&nbsp;file&nbsp;is&nbsp;stored&nbsp;the&nbsp;last&nbsp;time,&nbsp;which&nbsp;is&nbsp;the&nbsp;number&nbsp;of&nbsp;milliseconds&nbsp;elapsed&nbsp;since&nbsp;1970/01/01&nbsp;00:00:00&nbsp;GMT. |
| length | number | File&nbsp;size,&nbsp;in&nbsp;bytes. |
| type | string | File&nbsp;type.&nbsp;Available&nbsp;values&nbsp;are&nbsp;as&nbsp;follows:<br/>-&nbsp;**dir**:&nbsp;directory<br/>-&nbsp;**file**:&nbsp;file |
| uri | string | URI of the file.|
| lastModifiedTime | number | Timestamp when the file is saved the last time, which is the number of milliseconds elapsed since 1970/01/01 00:00:00 GMT.|
| length | number | File size, in bytes.|
| type | string | File type. Available values are as follows:<br>-&nbsp;**dir**: directory<br>-&nbsp;**file**: file |
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
| 301 | The file or directory does not exist.|
**Example**
......@@ -156,7 +154,7 @@ export default {
file.list({
uri: 'internal://app/pic',
success: function(data) {
console.log(data.fileList);
console.log(JSON.stringify(data.fileList));
},
fail: function(data, code) {
console.error('call fail callback fail, code: ' + code + ', data: ' + data);
......@@ -171,37 +169,37 @@ export default {
get(Object): void
Obtains information about a specified local file.
Obtains information about a local file.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | File&nbsp;URI. |
| recursive | boolean | No | Whether&nbsp;to&nbsp;recursively&nbsp;obtain&nbsp;the&nbsp;file&nbsp;list&nbsp;under&nbsp;a&nbsp;subdirectory.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of the file.|
| recursive | boolean | No| Whether to recursively obtain the file list under a subdirectory. The default value is **false**.|
| success | Function | No| Called when the file information is obtained.|
| fail | Function | No| Called when the file information fails to be obtained.|
| complete | Function | No| Called when the execution is complete.|
Return values of the **success** callback
Return values of the **success** callback:
| Name | Type | Description |
| Name| Type| Description|
| -------- | -------- | -------- |
| uri | string | File&nbsp;URI. |
| length | number | File&nbsp;size,&nbsp;in&nbsp;bytes. |
| lastModifiedTime | number | Timestamp&nbsp;when&nbsp;the&nbsp;file&nbsp;is&nbsp;stored&nbsp;the&nbsp;last&nbsp;time,&nbsp;which&nbsp;is&nbsp;the&nbsp;number&nbsp;of&nbsp;milliseconds&nbsp;elapsed&nbsp;since&nbsp;1970/01/01&nbsp;00:00:00&nbsp;GMT. |
| type | string | File&nbsp;type.&nbsp;The&nbsp;values&nbsp;are&nbsp;as&nbsp;follows:<br/>-&nbsp;**dir**:&nbsp;directory<br/>-&nbsp;**file**:&nbsp;file |
| subFiles | Array | File&nbsp;list. |
| uri | string | URI of the file.|
| length | number | File size, in bytes.|
| lastModifiedTime | number | Timestamp when the file is saved the last time, which is the number of milliseconds elapsed since 1970/01/01 00:00:00 GMT.|
| type | string | File type. Available values are as follows:<br>-&nbsp;**dir**: directory<br>-&nbsp;**file**: file |
| subFiles | Array | List of files.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
| 301 | The file or directory does not exist.|
**Example**
......@@ -226,26 +224,26 @@ export default {
delete(Object): void
Deletes local files.
Deletes a local file.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;file&nbsp;to&nbsp;delete,&nbsp;which&nbsp;cannot&nbsp;be&nbsp;an&nbsp;application&nbsp;resource&nbsp;path. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of the file to delete. It cannot be an application resource path.|
| success | Function | No| Called when the file is deleted.|
| fail | Function | No| Called when the file fails to be deleted.|
| complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Incorrect&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
| 301 | The file or directory does not exist.|
**Example**
......@@ -270,28 +268,28 @@ export default {
writeText(Object): void
Writes text into a specified file.
Writes text into a file. Only text files can be read and written.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;a&nbsp;local&nbsp;file.&nbsp;If&nbsp;it&nbsp;does&nbsp;not&nbsp;exist,&nbsp;a&nbsp;file&nbsp;will&nbsp;be&nbsp;created. |
| text | string | Yes | Character&nbsp;string&nbsp;to&nbsp;write&nbsp;into&nbsp;the&nbsp;local&nbsp;file. |
| encoding | string | No | Encoding&nbsp;format.&nbsp;The&nbsp;default&nbsp;format&nbsp;is&nbsp;UTF-8. |
| append | boolean | No | Whether&nbsp;to&nbsp;enable&nbsp;the&nbsp;append&nbsp;mode.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of a local file. If it does not exist, a file will be created.|
| text | string | Yes| Text to write into the file. |
| encoding | string | No| Encoding format. The default format is **UTF-8**.|
| append | boolean | No| Whether to enable the append mode. The default value is **false**.|
| success | Function | No| Called when the text is written into the specified file.|
| fail | Function | No| Called when the text fails to be written into the file.|
| complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Incorrect&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
**Example**
......@@ -317,28 +315,28 @@ export default {
writeArrayBuffer(Object): void
Writes buffer data into a specified file.
Writes buffer data into a file. Only text files can be read and written.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;a&nbsp;local&nbsp;file.&nbsp;If&nbsp;it&nbsp;does&nbsp;not&nbsp;exist,&nbsp;a&nbsp;file&nbsp;will&nbsp;be&nbsp;created. |
| buffer | Uint8Array | Yes | Buffer&nbsp;from&nbsp;which&nbsp;the&nbsp;data&nbsp;is&nbsp;derived. |
| position | number | No | Offset&nbsp;to&nbsp;the&nbsp;position&nbsp;where&nbsp;the&nbsp;writing&nbsp;starts.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**0**. |
| append | boolean | No | Whether&nbsp;to&nbsp;enable&nbsp;the&nbsp;append&nbsp;mode.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**.&nbsp;If&nbsp;the&nbsp;value&nbsp;is&nbsp;**true**,&nbsp;the&nbsp;**position**&nbsp;parameter&nbsp;will&nbsp;become&nbsp;invalid. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of a local file. If it does not exist, a file will be created.|
| buffer | Uint8Array | Yes| Buffer from which the data is derived.|
| position | number | No| Offset to the position where the writing starts. The default value is **0**.|
| append | boolean | No| Whether to enable the append mode. The default value is **false**. If the value is **true**, the **position** parameter will become invalid.|
| success | Function | No| Called when buffer data is written into the file. |
| fail | Function | No| Called when buffer data fails to be written into the file.|
| complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
**Example**
......@@ -347,7 +345,7 @@ export default {
writeArrayBuffer() {
file.writeArrayBuffer({
uri: 'internal://app/test',
buffer: new Uint8Array(8), // The buffer is of the Uint8Array type.
buffer: new Uint8Array(8), // The buffer is of the Uint8Array type.
success: function() {
console.log('call writeArrayBuffer success.');
},
......@@ -364,36 +362,36 @@ export default {
readText(Object): void
Reads text from a specified file.
Reads text from a file. Only text files can be read and written.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;a&nbsp;local&nbsp;file. |
| encoding | string | No | Encoding&nbsp;format.&nbsp;The&nbsp;default&nbsp;format&nbsp;is&nbsp;UTF-8. |
| position | number | No | Position&nbsp;where&nbsp;the&nbsp;reading&nbsp;starts.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;the&nbsp;start&nbsp;position&nbsp;of&nbsp;the&nbsp;file. |
| length | number | No | Length&nbsp;of&nbsp;the&nbsp;text&nbsp;to&nbsp;be&nbsp;read&nbsp;(in&nbsp;bytes).&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**4096**. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of a local file.|
| encoding | string | No| Encoding format. The default format is **UTF-8**.|
| position | number | No| Position where the reading starts. The default value is the start position of the file.|
| length | number | No| Length of the text to read, in bytes. The default value is **4096**.|
| success | Function | No| Called when the text is read successfully.|
| fail | Function | No| Called when the text failed to be read.|
| complete | Function | No| Called when the execution is complete.|
Return values of the **success** callback
Return values of the **success** callback:
| Name | Type | Description |
| Name| Type| Description|
| -------- | -------- | -------- |
| text | string | Text&nbsp;read&nbsp;from&nbsp;the&nbsp;specified&nbsp;file. |
| text | string | Text read from the specified file.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 301 | The&nbsp;file&nbsp;or&nbsp;directory&nbsp;does&nbsp;not&nbsp;exist. |
| 302 | The&nbsp;size&nbsp;of&nbsp;text&nbsp;to&nbsp;read&nbsp;exceeds&nbsp;4096&nbsp;bytes. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
| 301 | The file or directory does not exist.|
| 302 | The text to read exceeds 4 KB.|
**Example**
......@@ -418,34 +416,34 @@ export default {
readArrayBuffer(Object): void
Reads buffer data from a specified file.
Reads buffer data from a file. Only text files can be read and written.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;a&nbsp;local&nbsp;file. |
| position | number | No | Position&nbsp;where&nbsp;the&nbsp;reading&nbsp;starts.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;the&nbsp;start&nbsp;position&nbsp;of&nbsp;the&nbsp;file. |
| length | number | No | Length&nbsp;of&nbsp;data&nbsp;to&nbsp;read.&nbsp;If&nbsp;this&nbsp;parameter&nbsp;is&nbsp;not&nbsp;set,&nbsp;the&nbsp;reading&nbsp;proceeds&nbsp;until&nbsp;the&nbsp;end&nbsp;of&nbsp;the&nbsp;file. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of a local file.|
| position | number | No| Position where the reading starts. The default value is the start position of the file.|
| length | number | No| Length of data to read. If this parameter is not set, the reading proceeds until the end of the file.|
| success | Function | No| Called when the buffer data is read successfully.|
| fail | Function | No| Called when the buffer data fails to be read.|
| complete | Function | No| Called when the execution is complete.|
Return values of the **success** callback
Return values of the **success** callback:
| Name | Type | Description |
| Name| Type| Description|
| -------- | -------- | -------- |
| buffer | Uint8Array | File&nbsp;content&nbsp;that&nbsp;is&nbsp;read |
| buffer | Uint8Array | Data read.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
| 301 | The file or directory does not exist.|
**Example**
......@@ -472,26 +470,26 @@ export default {
access(Object): void
Checks whether a specified file or directory exists.
Checks whether a file or directory exists.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;directory&nbsp;or&nbsp;file. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of the directory or file to check.|
| success | Function | No| Called when the operation is successful.|
| fail | Function | No| Called when the operation fails.|
| complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
| 301 | The file or directory does not exist.|
**Example**
......@@ -516,26 +514,26 @@ export default {
mkdir(Object): void
Creates a specified directory.
Creates a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;directory. |
| recursive | boolean | No | Whether&nbsp;to&nbsp;recursively&nbsp;create&nbsp;upper-level&nbsp;directories&nbsp;of&nbsp;the&nbsp;specified&nbsp;directory.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of the directory to create.|
| recursive | boolean | No| Whether to recursively create upper-level directories of the specified directory. The default value is **false**.|
| success | Function | No| Called when the directory is created.|
| fail | Function | No| Called when the directory fails to be created.|
| complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
**Example**
......@@ -560,27 +558,27 @@ export default {
rmdir(Object): void
Deletes a specified directory.
Deletes a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;directory. |
| recursive | boolean | No | Whether&nbsp;to&nbsp;recursively&nbsp;delete&nbsp;subfiles&nbsp;and&nbsp;subdirectories&nbsp;of&nbsp;the&nbsp;specified&nbsp;directory.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**. |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
| uri | string | Yes| URI of the directory to delete.|
| recursive | boolean | No| Whether to recursively delete files and subdirectories of the specified directory. The default value is **false**.|
| success | Function | No| Called when the directory is deleted.|
| fail | Function | No| Called when the directory fails to be deleted.|
| complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails.
Error code returned:
| Error&nbsp;Code | Description |
| Error Code| Description|
| -------- | -------- |
| 202 | Invalid&nbsp;parameter. |
| 300 | I/O&nbsp;error. |
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. |
| 202 | Incorrect parameters are detected.|
| 300 | An I/O error occurs.|
| 301 | The file or directory does not exist.|
**Example**
......@@ -598,4 +596,4 @@ export default {
});
}
}
```
\ No newline at end of file
```
......@@ -6,7 +6,7 @@
> - API version 9 is a canary version for trial use. The APIs of this version may be unstable.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
This module provides APIs to implement volume and disk management, including obtaining volume information, mounting and unmounting volumes, partitioning disks, and formatting volumes.
Performs volume and disk management, including obtaining volume information, mounting and unmounting volumes, partitioning disks, and formatting volumes.
## Modules to Import
......@@ -54,7 +54,7 @@ Asynchronously obtains information about all available volumes. This API uses a
```js
let uuid = "";
volumemanager.getAllVolumes(uuid, function(error, volumes){
volumemanager.getAllVolumes(function(error, volumes){
// do something
});
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册