“7a89a0a7be405aaf42a359c4811b55486d0ffc17”上不存在“python/paddle/fluid/git@gitcode.net:Crayonxin2000/Paddle.git”
提交 cc890f14 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 7d18c4c3
# File Management File Management
> **NOTE**<br> > **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. > 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 ## Modules to Import
...@@ -14,30 +14,22 @@ import fileio from '@ohos.fileio'; ...@@ -14,30 +14,22 @@ import fileio from '@ohos.fileio';
## Guidelines ## 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). 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
Application sandbox path of a file or directory = Application directory + File name or directory name import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
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: let path = '';
context.getFilesDir().then((data) => {
```js path = data;
let path = dir + "/xxx.txt"; })
``` ```
The file descriptor is as follows:
```js
let fd = fileio.openSync(path);
```
## fileio.stat ## fileio.stat
stat(path: string): Promise&lt;Stat&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -45,7 +37,7 @@ Asynchronously obtains file information. This API uses a promise to return the r ...@@ -45,7 +37,7 @@ Asynchronously obtains file information. This API uses a promise to return the r
| Name| Type | Mandatory| Description | | 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** **Return value**
...@@ -56,9 +48,9 @@ Asynchronously obtains file information. This API uses a promise to return the r ...@@ -56,9 +48,9 @@ Asynchronously obtains file information. This API uses a promise to return the r
**Example** **Example**
```js ```js
fileio.stat(path).then(function(stat){ fileio.stat(path).then(function(stat){
console.info("getFileInfo successfully:"+ JSON.stringify(stat)); console.info("Got file info:"+ JSON.stringify(stat));
}).catch(function(err){ }).catch(function(err){
console.info("getFileInfo failed with error:"+ err); console.info("Failed to get file info. Error:"+ err);
}); });
``` ```
...@@ -67,14 +59,14 @@ Asynchronously obtains file information. This API uses a promise to return the r ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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.| | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
**Example** **Example**
...@@ -96,7 +88,7 @@ Synchronously obtains file information. ...@@ -96,7 +88,7 @@ Synchronously obtains file information.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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** **Return value**
...@@ -115,7 +107,7 @@ Synchronously obtains file information. ...@@ -115,7 +107,7 @@ Synchronously obtains file information.
opendir(path: string): Promise&lt;Dir&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -127,14 +119,14 @@ Asynchronously opens a directory. This API uses a promise to return the result. ...@@ -127,14 +119,14 @@ Asynchronously opens a directory. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | 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** **Example**
```js ```js
fileio.opendir(path).then(function(dir){ fileio.opendir(path).then(function(dir){
console.info("opendir successfully:"+ JSON.stringify(dir)); console.info("Directory opened:"+ JSON.stringify(dir));
}).catch(function(err){ }).catch(function(err){
console.info("opendir failed with error:"+ err); console.info("Failed to open the directory. Error:"+ err);
}); });
``` ```
...@@ -143,7 +135,7 @@ Asynchronously opens a directory. This API uses a promise to return the result. ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -195,7 +187,7 @@ Synchronously opens a directory. ...@@ -195,7 +187,7 @@ Synchronously opens a directory.
access(path: string, mode?: number): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -203,20 +195,20 @@ Asynchronously checks whether the current process can access a file. This API us ...@@ -203,20 +195,20 @@ Asynchronously checks whether the current process can access a file. This API us
| Name| Type | Mandatory| Description | | 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.| | 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** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.access(path).then(function() { fileio.access(path).then(function() {
console.info("access successfully"); console.info("Access successful");
}).catch(function(err){ }).catch(function(err){
console.info("access failed with error:"+ err); console.info("Access failed. Error:"+ err);
}); });
``` ```
...@@ -225,14 +217,14 @@ Asynchronously checks whether the current process can access a file. This API us ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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.| | 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. | | 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. ...@@ -255,7 +247,7 @@ Synchronously checks whether the current process can access the specified file.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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.| | 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** **Example**
...@@ -263,7 +255,7 @@ Synchronously checks whether the current process can access the specified file. ...@@ -263,7 +255,7 @@ Synchronously checks whether the current process can access the specified file.
try { try {
fileio.accessSync(path); fileio.accessSync(path);
} catch(err) { } catch(err) {
console.info("accessSync failed with error:"+ err); console.info("accessSync failed. Error:"+ err);
} }
``` ```
...@@ -272,7 +264,7 @@ Synchronously checks whether the current process can access the specified file. ...@@ -272,7 +264,7 @@ Synchronously checks whether the current process can access the specified file.
close(fd: number):Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -284,15 +276,15 @@ Asynchronously closes a file. This API uses a promise to return the result. ...@@ -284,15 +276,15 @@ Asynchronously closes a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.close(fd).then(function(){ fileio.close(fd).then(function(){
console.info("close file successfully"); console.info("File closed");
}).catch(function(err){ }).catch(function(err){
console.info("close file failed with error:"+ err); console.info("Failed to close the file. Error:"+ err);
}); });
``` ```
...@@ -301,7 +293,7 @@ Asynchronously closes a file. This API uses a promise to return the result. ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -343,21 +335,21 @@ Synchronously closes a file. ...@@ -343,21 +335,21 @@ Synchronously closes a file.
close(): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.close().then(function(){ fileio.close().then(function(){
console.info("close file stream successfully"); console.info("File stream closed");
}).catch(function(err){ }).catch(function(err){
console.info("close file stream failed with error:"+ err); console.info("Failed to close the file stream. Error:"+ err);
}); });
``` ```
...@@ -366,7 +358,7 @@ Asynchronously closes the stream. This API uses a promise to return the result. ...@@ -366,7 +358,7 @@ Asynchronously closes the stream. This API uses a promise to return the result.
close(callback: AsyncCallback&lt;void&gt;): void 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -387,7 +379,7 @@ Asynchronously closes the stream. This API uses a callback to return the result. ...@@ -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; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -401,14 +393,14 @@ Asynchronously copies a file. This API uses a promise to return the result. ...@@ -401,14 +393,14 @@ Asynchronously copies a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.copyFile(src, dest).then(function(){ fileio.copyFile(src, dest).then(function(){
console.info("copyFile successfully"); console.info("File copied");
}).catch(function(err){ }).catch(function(err){
console.info("copyFile failed with error:"+ err); console.info("Failed to copy the file. Error:"+ err);
}); });
``` ```
...@@ -417,7 +409,7 @@ Asynchronously copies a file. This API uses a promise to return the result. ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -462,27 +454,27 @@ Synchronously copies a file. ...@@ -462,27 +454,27 @@ Synchronously copies a file.
mkdir(path:string, mode?: number): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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.| | 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** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.mkdir(path).then(function() { fileio.mkdir(path).then(function() {
console.info("mkdir successfully"); console.info("Directory created");
}).catch(function (error){ }).catch(function (error){
console.info("mkdir failed with error:"+ error); console.info("Failed to create the directory. Error:"+ error);
}); });
``` ```
...@@ -491,21 +483,21 @@ Asynchronously creates a directory. This API uses a promise to return the result ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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.| | 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. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. |
**Example** **Example**
```js ```js
fileio.mkdir(path, function(err) { fileio.mkdir(path, function(err) {
console.info("mkdir successfully"); console.info("Directory created");
}); });
``` ```
...@@ -521,7 +513,7 @@ Synchronously creates a directory. ...@@ -521,7 +513,7 @@ Synchronously creates a directory.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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.| | 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** **Example**
...@@ -534,28 +526,28 @@ Synchronously creates a directory. ...@@ -534,28 +526,28 @@ Synchronously creates a directory.
open(path: string, flags?: number, mode?: number): Promise&lt;number&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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.| | 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** does not point 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.| | 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** **Return value**
| Type | Description | | 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** **Example**
```js ```js
fileio.open(path, 0o1, 0o0200).then(function(number){ fileio.open(path, 0o1, 0o0200).then(function(number){
console.info("open file successfully"); console.info("File opened");
}).catch(function(error){ }).catch(function(err){
console.info("open file failed with error:"+ err); console.info("Failed to open the file. Error:"+ err);
}); });
``` ```
...@@ -564,15 +556,15 @@ Asynchronously opens a file. This API uses a promise to return the result. ...@@ -564,15 +556,15 @@ 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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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.| | 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** does not point 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.| | 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. | | callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file is open asynchronously. |
...@@ -595,9 +587,9 @@ Synchronously opens a file. ...@@ -595,9 +587,9 @@ Synchronously opens a file.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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.| | 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** does not point 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** **Return value**
| Type | Description | | Type | Description |
...@@ -606,7 +598,15 @@ Synchronously opens a file. ...@@ -606,7 +598,15 @@ Synchronously opens a file.
**Example** **Example**
```js ```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?: { ...@@ -618,7 +618,7 @@ read(fd: number, buffer: ArrayBuffer, options?: {
position?: number; position?: number;
}): Promise&lt;ReadOut&gt; }): 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -633,17 +633,17 @@ Asynchronously reads data from a file. This API uses a promise to return the res ...@@ -633,17 +633,17 @@ Asynchronously reads data from a file. This API uses a promise to return the res
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.| | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(fd, buf).then(function(readout){ fileio.read(fd, buf).then(function(readOut){
console.info("read file data successfully"); console.info("Read file data");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(error){ }).catch(function(err){
console.info("read file data failed with error:"+ error); console.info("Failed to read file data. Error:"+ err);
}); });
``` ```
...@@ -656,7 +656,7 @@ read(fd: number, buffer: ArrayBuffer, options: { ...@@ -656,7 +656,7 @@ read(fd: number, buffer: ArrayBuffer, options: {
position?: number; position?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void }, 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 **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 ...@@ -674,7 +674,7 @@ Asynchronously reads data from a file. This API uses a callback to return the re
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(fd, buf, function (err, readOut) { fileio.read(fd, buf, function (err, readOut) {
if (readOut) { if (readOut) {
console.info("read file data successfully"); console.info("Read file data");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
} }
}); });
...@@ -717,26 +717,26 @@ Synchronously reads data from a file. ...@@ -717,26 +717,26 @@ Synchronously reads data from a file.
rmdir(path: string): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory to delete.| | path | string | Yes | Application sandbox path of the directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.rmdir(path).then(function() { fileio.rmdir(path).then(function() {
console.info("rmdir successfully"); console.info("Directory deleted");
}).catch(function(err){ }).catch(function(err){
console.info("rmdir failed with error:"+ err); console.info("Failed to delete the directory. Error:"+ err);
}); });
``` ```
...@@ -745,21 +745,21 @@ Asynchronously deletes a directory. This API uses a promise to return the result ...@@ -745,21 +745,21 @@ Asynchronously deletes a directory. This API uses a promise to return the result
rmdir(path: string, callback:AsyncCallback&lt;void&gt;): void 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- | | -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory to delete.| | path | string | Yes | Application sandbox path of the directory.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously. |
**Example** **Example**
```js ```js
fileio.rmdir(path, function(err){ fileio.rmdir(path, function(err){
// Do something. // Do something.
console.info("rmdir successfully"); console.info("Directory deleted");
}); });
``` ```
...@@ -775,7 +775,7 @@ Synchronously deletes a directory. ...@@ -775,7 +775,7 @@ Synchronously deletes a directory.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory to delete.| | path | string | Yes | Application sandbox path of the directory.|
**Example** **Example**
```js ```js
...@@ -787,26 +787,26 @@ Synchronously deletes a directory. ...@@ -787,26 +787,26 @@ Synchronously deletes a directory.
unlink(path:string): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file to delete.| | path | string | Yes | Application sandbox path of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.unlink(path).then(function(){ fileio.unlink(path).then(function(){
console.info("remove file successfully"); console.info("File deleted");
}).catch(function(error){ }).catch(function(error){
console.info("remove file failed with error:"+ error); console.info("Failed to delete the file. Error:"+ error);
}); });
``` ```
...@@ -815,20 +815,20 @@ Asynchronously deletes a file. This API uses a promise to return the result. ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is deleted asynchronously. |
**Example** **Example**
```js ```js
fileio.unlink(path, function(err) { fileio.unlink(path, function(err) {
console.info("remove file successfully"); console.info("File deleted");
}); });
``` ```
...@@ -844,7 +844,7 @@ Synchronously deletes a file. ...@@ -844,7 +844,7 @@ Synchronously deletes a file.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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** **Example**
```js ```js
...@@ -861,7 +861,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: { ...@@ -861,7 +861,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
encoding?: string; encoding?: string;
}): Promise&lt;number&gt; }): 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -875,15 +875,15 @@ Asynchronously writes data into a file. This API uses a promise to return the re ...@@ -875,15 +875,15 @@ Asynchronously writes data into a file. This API uses a promise to return the re
**Return value** **Return value**
| Type | Description | | 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** **Example**
```js ```js
let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world").then(function(number){ fileio.write(fd, "hello, world").then(function(number){
console.info("write data to file successfully and size is:"+ number); console.info("Data written to file and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("write data to file failed with error:"+ err); console.info("Failed to write data to the file. Error:"+ err);
}); });
``` ```
...@@ -897,7 +897,7 @@ write(fd: number, buffer: ArrayBuffer | string, options: { ...@@ -897,7 +897,7 @@ write(fd: number, buffer: ArrayBuffer | string, options: {
encoding?: string; encoding?: string;
}, callback: AsyncCallback&lt;number&gt;): void }, 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 **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 ...@@ -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); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world", function (err, bytesWritten) { fileio.write(fd, "hello, world", function (err, bytesWritten) {
if (bytesWritten) { if (bytesWritten) {
console.info("write data to file successfully and size is:"+ bytesWritten); console.info("Data written to file and size is:"+ bytesWritten);
} }
}); });
``` ```
...@@ -956,27 +956,27 @@ Synchronously writes data into a file. ...@@ -956,27 +956,27 @@ Synchronously writes data into a file.
hash(path: string, algorithm: string): Promise&lt;string&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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.| | 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** **Return value**
| Type | Description | | 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** **Example**
```js ```js
fileio.hash(path, "sha256").then(function(str){ fileio.hash(path, "sha256").then(function(str){
console.info("calculate file hash successfully:"+ str); console.info("Calculated file hash:"+ str);
}).catch(function(error){ }).catch(function(error){
console.info("calculate file hash failed with error:"+ err); console.info("Failed to calculate the file hash. Error:"+ err);
}); });
``` ```
...@@ -985,22 +985,22 @@ Asynchronously calculates the hash value of a file. This API uses a promise to r ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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.| | 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** **Example**
```js ```js
fileio.hash(fpath, "sha256", function(err, hashStr) { fileio.hash(path, "sha256", function(err, hashStr) {
if (hashStr) { if (hashStr) {
console.info("calculate file hash successfully:"+ hashStr); console.info("Calculated file hash:"+ hashStr);
} }
}); });
``` ```
...@@ -1010,27 +1010,27 @@ Asynchronously calculates the hash value of a file. This API uses a callback to ...@@ -1010,27 +1010,27 @@ Asynchronously calculates the hash value of a file. This API uses a callback to
chmod(path: string, mode: number):Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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.| | 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** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.chmod(path, mode).then(function() { fileio.chmod(path, mode).then(function() {
console.info("chmod successfully"); console.info("File permissions changed");
}).catch(function(err){ }).catch(function(err){
console.info("chmod failed with error:"+ err); console.info("Failed to change file permissions. Error:"+ err);
}); });
``` ```
...@@ -1039,14 +1039,14 @@ Asynchronously changes the file permissions based on its path. This API uses a p ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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.| | 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. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
...@@ -1062,19 +1062,19 @@ Asynchronously changes the file permissions based on its path. This API uses a c ...@@ -1062,19 +1062,19 @@ Asynchronously changes the file permissions based on its path. This API uses a c
chmodSync(path: string, mode: number): void 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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.| | 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** **Example**
```js ```js
fileio.chmodSync(fpath, mode); fileio.chmodSync(path, mode);
``` ```
...@@ -1082,7 +1082,7 @@ Synchronously changes the file permissions based on its path. ...@@ -1082,7 +1082,7 @@ Synchronously changes the file permissions based on its path.
fstat(fd: number): Promise&lt;Stat&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1094,14 +1094,14 @@ Asynchronously obtains file information based on the file descriptor. This API u ...@@ -1094,14 +1094,14 @@ Asynchronously obtains file information based on the file descriptor. This API u
**Return value** **Return value**
| Type | Description | | 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** **Example**
```js ```js
fileio.fstat(fd).then(function(stat){ fileio.fstat(fd).then(function(stat){
console.info("fstat successfully:"+ JSON.stringify(stat)); console.info("File information obtained:"+ JSON.stringify(stat));
}).catch(function(err){ }).catch(function(err){
console.info("fstat failed with error:"+ err); console.info("Failed to obtain file information. Error:"+ err);
}); });
``` ```
...@@ -1110,7 +1110,7 @@ Asynchronously obtains file information based on the file descriptor. This API u ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1158,7 +1158,7 @@ Synchronously obtains file information based on the file descriptor. ...@@ -1158,7 +1158,7 @@ Synchronously obtains file information based on the file descriptor.
ftruncate(fd: number, len?: number): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1166,18 +1166,18 @@ Asynchronously truncates a file based on the file descriptor. This API uses a pr ...@@ -1166,18 +1166,18 @@ Asynchronously truncates a file based on the file descriptor. This API uses a pr
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- | | ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | 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** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.ftruncate(fd, 5).then(function(err) { fileio.ftruncate(fd, 5).then(function(err) {
console.info("File truncated successfully."); console.info("File truncated");
}).catch(function(err){ }).catch(function(err){
console.info("Failed to truncate the file. Error:"+ 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 ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1197,7 +1197,7 @@ Asynchronously truncates a file based on the file descriptor. This API uses a ca ...@@ -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. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.| | 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 that returns no value. |
**Example** **Example**
```js ```js
...@@ -1231,7 +1231,7 @@ Synchronously truncates a file based on the file descriptor. ...@@ -1231,7 +1231,7 @@ Synchronously truncates a file based on the file descriptor.
truncate(path: string, len?: number): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **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 ...@@ -1239,17 +1239,17 @@ Asynchronously truncates a file based on its path. This API uses a promise to re
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- | | ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate. | | 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** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.truncate(path, len).then(function(){ fileio.truncate(path, len).then(function(){
console.info("File truncated successfully."); console.info("File truncated");
}).catch(function(err){ }).catch(function(err){
console.info("Failed to truncate the file. Error:"+ err); console.info("Failed to truncate the file. Error:"+ err);
}); });
...@@ -1260,16 +1260,16 @@ Asynchronously truncates a file based on its path. This API uses a promise to re ...@@ -1260,16 +1260,16 @@ 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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------- | | -------- | ------------------------- | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate. | | path | string | Yes | Application sandbox path of the file to truncate.|
| len | number | Yes | File length, in bytes, after truncation.| | 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 that returns no value. |
**Example** **Example**
```js ```js
...@@ -1290,7 +1290,7 @@ Synchronously truncates a file based on the file path. ...@@ -1290,7 +1290,7 @@ Synchronously truncates a file based on the file path.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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.| | len | number | No | File length, in bytes, after truncation.|
**Example** **Example**
...@@ -1307,7 +1307,7 @@ readText(filePath: string, options?: { ...@@ -1307,7 +1307,7 @@ readText(filePath: string, options?: {
encoding?: string; encoding?: string;
}): Promise&lt;string&gt; }): 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1320,14 +1320,14 @@ Asynchronously reads the text of a file. This API uses a promise to return the r ...@@ -1320,14 +1320,14 @@ Asynchronously reads the text of a file. This API uses a promise to return the r
**Return value** **Return value**
| Type | Description | | 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** **Example**
```js ```js
fileio.readText(path).then(function(str) { fileio.readText(path).then(function(str) {
console.info("readText successfully:"+ str); console.info("Read file text:"+ str);
}).catch(function(err){ }).catch(function(err){
console.info("readText failed with error:"+ err); console.info("Failed to read text. Error:"+ err);
}); });
``` ```
...@@ -1340,7 +1340,7 @@ readText(filePath: string, options: { ...@@ -1340,7 +1340,7 @@ readText(filePath: string, options: {
encoding?: string; encoding?: string;
}, callback: AsyncCallback&lt;string&gt;): void }, 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 **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 ...@@ -1348,8 +1348,8 @@ Asynchronously reads the text of a file. This API uses a callback to return the
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to read. | | 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.| | 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 invoked when the file is read asynchronously. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the content read. |
**Example** **Example**
```js ```js
...@@ -1374,7 +1374,7 @@ Synchronously reads the text of a file. ...@@ -1374,7 +1374,7 @@ Synchronously reads the text of a file.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to be read. | | 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.| | 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.|
**Return value** **Return value**
...@@ -1392,24 +1392,24 @@ Synchronously reads the text of a file. ...@@ -1392,24 +1392,24 @@ Synchronously reads the text of a file.
lstat(path: string): Promise&lt;Stat&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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** **Return value**
| Type | Description | | 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** **Example**
```js ```js
fileio.lstat(path).then(function(stat){ fileio.lstat(path).then(function(stat){
console.info("Link status obtained:"+ number); console.info("Got link info:"+ JSON.stringify(stat));
}).catch(function(err){ }).catch(function(err){
console.info("Failed to obtain the link status. Error:"+ err); console.info("Failed to obtain the link status. Error:"+ err);
}); });
...@@ -1420,15 +1420,15 @@ Asynchronously obtains link information. This API uses a promise to return the r ...@@ -1420,15 +1420,15 @@ Asynchronously obtains link information. This API uses a promise to return the r
lstat(path:string, callback:AsyncCallback&lt;Stat&gt;): void 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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.|
| 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** **Example**
```js ```js
...@@ -1449,7 +1449,7 @@ Synchronously obtains the link information. ...@@ -1449,7 +1449,7 @@ Synchronously obtains the link information.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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** **Return value**
| Type | Description | | Type | Description |
...@@ -1470,7 +1470,7 @@ read(buffer: ArrayBuffer, options?: { ...@@ -1470,7 +1470,7 @@ read(buffer: ArrayBuffer, options?: {
length?: number; length?: number;
}): Promise&lt;ReadOut&gt; }): 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **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 ...@@ -1483,12 +1483,12 @@ Asynchronously reads data from a file. This API uses a promise to return the res
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.| | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example** **Example**
```js ```js
fileio.read(new ArrayBuffer(4096)).then(function(readout){ fileio.read(new ArrayBuffer(4096)).then(function(readout){
console.info("read file data successfully"); console.info("Read file data");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){ }).catch(function(err){
console.info("Failed to read file data. Error:"+ err); console.info("Failed to read file data. Error:"+ err);
...@@ -1504,7 +1504,7 @@ read(buffer: ArrayBuffer, options: { ...@@ -1504,7 +1504,7 @@ read(buffer: ArrayBuffer, options: {
length?: number; length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void }, 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 **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 ...@@ -1520,7 +1520,7 @@ Asynchronously reads data from a file. This API uses a callback to return the re
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(buf, function (err, readOut) { fileio.read(buf, function (err, readOut) {
if (readOut) { if (readOut) {
console.info("read file data successfully"); console.info("Read file data");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); 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 ...@@ -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; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1544,14 +1544,14 @@ Asynchronously renames a file. This API uses a promise to return the result. ...@@ -1544,14 +1544,14 @@ Asynchronously renames a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.rename(oldPath, newPath).then(function() { fileio.rename(oldPath, newPath).then(function() {
console.info("rename successfully"); console.info("File renamed");
}).catch(function(err){ }).catch(function(err){
console.info("rename failed with error:"+ err); console.info("Failed to rename the file. Error:"+ err);
}); });
``` ```
...@@ -1560,7 +1560,7 @@ Asynchronously renames a file. This API uses a promise to return the result. ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1568,7 +1568,7 @@ Asynchronously renames a file. This API uses a callback to return the result. ...@@ -1568,7 +1568,7 @@ Asynchronously renames a file. This API uses a callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------- | | -------- | ------------------------- | ---- | ---------------------------- |
| oldPath | string | Yes | Application sandbox path of the file to rename.| | 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. | | Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously renamed. |
**Example** **Example**
...@@ -1602,26 +1602,26 @@ Synchronously renames a file. ...@@ -1602,26 +1602,26 @@ Synchronously renames a file.
fsync(fd: number): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.fsync(fd).then(function(){ fileio.fsync(fd).then(function(){
console.info("sync data successfully"); console.info("Data flushed");
}).catch(function(err){ }).catch(function(err){
console.info("sync data failed with error:"+ err); console.info("Failed to flush data. Error:"+ err);
}); });
``` ```
...@@ -1630,14 +1630,14 @@ Asynchronously synchronizes a file. This API uses a promise to return the result ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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.| | Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is synchronized in asynchronous mode.|
**Example** **Example**
...@@ -1652,18 +1652,18 @@ Asynchronously synchronizes a file. This API uses a callback to return the resul ...@@ -1652,18 +1652,18 @@ Asynchronously synchronizes a file. This API uses a callback to return the resul
fsyncSync(fd: number): void 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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** **Example**
```js ```js
fileio.fyncsSync(fd); fileio.fsyncSync(fd);
``` ```
...@@ -1671,26 +1671,26 @@ Synchronizes a file in synchronous mode. ...@@ -1671,26 +1671,26 @@ Synchronizes a file in synchronous mode.
fdatasync(fd: number): Promise&lt;void&gt; 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. **fdatasync()** is similar to **fsync()**, but does not flush modified metadata unless that metadata is needed.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.fdatasync(fd).then(function(err) { fileio.fdatasync(fd).then(function(err) {
console.info("sync data successfully"); console.info("Data flushed");
}).catch(function(err){ }).catch(function(err){
console.info("sync data failed with error:"+ err); console.info("Failed to flush data. Error:"+ err);
}); });
``` ```
...@@ -1699,7 +1699,7 @@ Asynchronously synchronizes data in a file. This API uses a promise to return th ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1728,7 +1728,7 @@ Synchronizes data in a file in synchronous mode. ...@@ -1728,7 +1728,7 @@ Synchronizes data in a file in synchronous mode.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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** **Example**
```js ```js
...@@ -1740,27 +1740,27 @@ Synchronizes data in a file in synchronous mode. ...@@ -1740,27 +1740,27 @@ Synchronizes data in a file in synchronous mode.
symlink(target: string, srcPath: string): Promise&lt;void&gt; 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 the file path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- | | ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Application sandbox path of the symbolic link. | | target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Application sandbox path of the referenced file or directory contained in the symbolic link.| | srcPath | string | Yes | Application sandbox path of the symbolic link file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.symlink(target, srcPath).then(function() { fileio.symlink(target, srcPath).then(function() {
console.info("symlink successfully"); console.info("Symbolic link created");
}).catch(function(err){ }).catch(function(err){
console.info("symlink failed with error:"+ err); console.info("Failed to create the symbolic link. Error:"+ err);
}); });
``` ```
...@@ -1769,15 +1769,15 @@ Asynchronously creates a symbolic link based on a path. This API uses a promise ...@@ -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 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 the file path. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------- | | -------- | ------------------------- | ---- | -------------------------------- |
| target | string | Yes | Application sandbox path of the symbolic link. | | target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Application sandbox path of the referenced file or directory contained in the symbolic link. | | 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.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the symbolic link is created asynchronously.|
**Example** **Example**
...@@ -1799,8 +1799,8 @@ Synchronously creates a symbolic link based on a specified path. ...@@ -1799,8 +1799,8 @@ Synchronously creates a symbolic link based on a specified path.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- | | ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Application sandbox path of the symbolic link. | | target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Application sandbox path the referenced file or directory contained in the symbolic link.| | srcPath | string | Yes | Application sandbox path of the symbolic link file.|
**Example** **Example**
```js ```js
...@@ -1812,29 +1812,29 @@ Synchronously creates a symbolic link based on a specified path. ...@@ -1812,29 +1812,29 @@ Synchronously creates a symbolic link based on a specified path.
chown(path: string, uid: number, gid: number): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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). | | uid | number | Yes | New user ID (UID). |
| gid | number | Yes | New group ID (GID). | | gid | number | Yes | New group ID (GID). |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.chown(path, stat.uid, stat.gid).then(function(){ fileio.chown(path, stat.uid, stat.gid).then(function(){
console.info("chown successfully"); console.info("File owner changed");
}).catch(function(err){ }).catch(function(err){
console.info("chown failed with error:"+ err); console.info("Failed to change the file owner. Error:"+ err);
}); });
``` ```
...@@ -1843,21 +1843,21 @@ Asynchronously changes the file owner based on its path. This API uses a promise ...@@ -1843,21 +1843,21 @@ 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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(path)
fileio.chown(path, stat.uid, stat.gid, function (err){ fileio.chown(path, stat.uid, stat.gid, function (err){
// Do something. // Do something.
}); });
...@@ -1875,13 +1875,13 @@ Synchronously changes the file owner based on its path. ...@@ -1875,13 +1875,13 @@ Synchronously changes the file owner based on its path.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
**Example** **Example**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(path)
fileio.chownSync(path, stat.uid, stat.gid); fileio.chownSync(path, stat.uid, stat.gid);
``` ```
...@@ -1890,7 +1890,7 @@ Synchronously changes the file owner based on its path. ...@@ -1890,7 +1890,7 @@ Synchronously changes the file owner based on its path.
mkdtemp(prefix: string): Promise&lt;string&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1900,16 +1900,16 @@ Asynchronously creates a temporary directory. This API uses a promise to return ...@@ -1900,16 +1900,16 @@ Asynchronously creates a temporary directory. This API uses a promise to return
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Name | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Unique path generated.| | Promise&lt;string&gt; | Promise used to return the unique directory generated.|
**Example** **Example**
```js ```js
fileio.mkdtemp(path + "XXXX").then(function(path){ fileio.mkdtemp(path + "XXXX").then(function(path){
console.info("mkdtemp successfully:"+ path); console.info("Temporary directory created:"+ path);
}).catch(function(err){ }).catch(function(err){
console.info("mkdtemp failed with error:"+ err); console.info("Failed to create a temporary directory. Error:"+ err);
}); });
``` ```
...@@ -1918,7 +1918,7 @@ Asynchronously creates a temporary directory. This API uses a promise to return ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1950,7 +1950,7 @@ Synchronously creates a temporary directory. ...@@ -1950,7 +1950,7 @@ Synchronously creates a temporary directory.
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Name | Description | | Type | Description |
| ------ | ---------- | | ------ | ---------- |
| string | Unique path generated.| | string | Unique path generated.|
...@@ -1964,7 +1964,7 @@ Synchronously creates a temporary directory. ...@@ -1964,7 +1964,7 @@ Synchronously creates a temporary directory.
fchmod(fd: number, mode: number): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1975,16 +1975,16 @@ Asynchronously changes the file permissions based on the file descriptor. This A ...@@ -1975,16 +1975,16 @@ Asynchronously changes the file permissions based on the file descriptor. This A
| 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.| | 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** **Return value**
| Name | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.fchmod(fd, mode).then(function() { fileio.fchmod(fd, mode).then(function() {
console.info("chmod successfully"); console.info("File permissions changed");
}).catch(function(err){ }).catch(function(err){
console.info("chmod failed with error:"+ err); console.info("Failed to change file permissions. Error:"+ err);
}); });
``` ```
...@@ -1993,7 +1993,7 @@ Asynchronously changes the file permissions based on the file descriptor. This A ...@@ -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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2036,14 +2036,14 @@ Synchronously changes the file permissions based on the file descriptor. ...@@ -2036,14 +2036,14 @@ Synchronously changes the file permissions based on the file descriptor.
createStream(path: string, mode: string): Promise&lt;Stream&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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).| | 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** **Return value**
...@@ -2054,9 +2054,9 @@ Asynchronously opens a stream based on the file path. This API uses a promise to ...@@ -2054,9 +2054,9 @@ Asynchronously opens a stream based on the file path. This API uses a promise to
**Example** **Example**
```js ```js
fileio.createStream(path, "r+").then(function(stream){ fileio.createStream(path, "r+").then(function(stream){
console.info("createStream successfully"); console.info("Stream opened");
}).catch(function(err){ }).catch(function(err){
console.info("createStream failed with error:"+ err); console.info("Failed to create the stream. Error:"+ err);
}); });
``` ```
...@@ -2065,20 +2065,20 @@ Asynchronously opens a stream based on the file path. This API uses a promise to ...@@ -2065,20 +2065,20 @@ 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 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 file stream based on the file path. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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).| | 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. | | callback | AsyncCallback&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
**Example** **Example**
```js ```js
fileio.createStream(path, mode, function(err, stream){ fileio.createStream(path, "r+", function(err, stream){
// Do something. // Do something.
}); });
``` ```
...@@ -2095,11 +2095,11 @@ Synchronously opens a stream based on the file path. ...@@ -2095,11 +2095,11 @@ Synchronously opens a stream based on the file path.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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).| | 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** **Return value**
| Name | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream7) | Stream opened.| | [Stream](#stream7) | Stream opened.|
...@@ -2113,7 +2113,7 @@ Synchronously opens a stream based on the file path. ...@@ -2113,7 +2113,7 @@ Synchronously opens a stream based on the file path.
fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2124,16 +2124,17 @@ Asynchronously opens a stream based on the file descriptor. This API uses a prom ...@@ -2124,16 +2124,17 @@ Asynchronously opens a stream based on the file descriptor. This API uses a prom
| 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).| | 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** **Return value**
| Name | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
fileio.fdopenStream(fd, mode).then(function(stream){ let fd = fileio.openSync(path);
console.info("openStream successfully"); fileio.fdopenStream(fd, "r+").then(function(stream){
console.info("Stream opened");
}).catch(function(err){ }).catch(function(err){
console.info("openStream failed with error:"+ err); console.info("Failed to open the stream. Error:"+ err);
}); });
``` ```
...@@ -2142,7 +2143,7 @@ Asynchronously opens a stream based on the file descriptor. This API uses a prom ...@@ -2142,7 +2143,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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2155,7 +2156,8 @@ Asynchronously opens a stream based on the file descriptor. This API uses a call ...@@ -2155,7 +2156,8 @@ Asynchronously opens a stream based on the file descriptor. This API uses a call
**Example** **Example**
```js ```js
fileio.fdopenStream(fd, mode, function (err, stream) { let fd = fileio.openSync(path);
fileio.fdopenStream(fd, "r+", function (err, stream) {
// Do something. // Do something.
}); });
``` ```
...@@ -2182,6 +2184,7 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2182,6 +2184,7 @@ Synchronously opens a stream based on the file descriptor.
**Example** **Example**
```js ```js
let fd = fileio.openSync(path);
let ss = fileio.fdopenStreamSync(fd, "r+"); let ss = fileio.fdopenStreamSync(fd, "r+");
``` ```
...@@ -2190,7 +2193,7 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2190,7 +2193,7 @@ Synchronously opens a stream based on the file descriptor.
fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2204,15 +2207,15 @@ Asynchronously changes the file owner based on the file descriptor. This API use ...@@ -2204,15 +2207,15 @@ Asynchronously changes the file owner based on the file descriptor. This API use
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid).then(function() { fileio.fchown(fd, stat.uid, stat.gid).then(function() {
console.info("chown successfully"); console.info("File owner changed");
}).catch(function(err){ }).catch(function(err){
console.info("chown failed with error:"+ err); console.info("Failed to change the file owner. Error:"+ err);
}); });
``` ```
...@@ -2221,7 +2224,7 @@ Asynchronously changes the file owner based on the file descriptor. This API use ...@@ -2221,7 +2224,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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2235,7 +2238,7 @@ Asynchronously changes the file owner based on the file descriptor. This API use ...@@ -2235,7 +2238,7 @@ Asynchronously changes the file owner based on the file descriptor. This API use
**Example** **Example**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid, function (err){ fileio.fchown(fd, stat.uid, stat.gid, function (err){
// Do something. // Do something.
}); });
...@@ -2259,7 +2262,7 @@ Synchronously changes the file owner based on the file descriptor. ...@@ -2259,7 +2262,7 @@ Synchronously changes the file owner based on the file descriptor.
**Example** **Example**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(path);
fileio.fchownSync(fd, stat.uid, stat.gid); fileio.fchownSync(fd, stat.uid, stat.gid);
``` ```
...@@ -2268,29 +2271,29 @@ Synchronously changes the file owner based on the file descriptor. ...@@ -2268,29 +2271,29 @@ Synchronously changes the file owner based on the file descriptor.
lchown(path: string, uid: number, gid: number): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.lchown(path, stat.uid, stat.gid).then(function() { fileio.lchown(path, stat.uid, stat.gid).then(function() {
console.info("chown successfully"); console.info("File owner changed");
}).catch(function(err){ }).catch(function(err){
console.info("chown failed with error:"+ err); console.info("Failed to change the file owner. Error:"+ err);
}); });
``` ```
...@@ -2299,14 +2302,14 @@ Asynchronously changes the file owner based on the file path, changes the owner ...@@ -2299,14 +2302,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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
...@@ -2331,7 +2334,7 @@ Synchronously changes the file owner based on the file path and changes the owne ...@@ -2331,7 +2334,7 @@ Synchronously changes the file owner based on the file path and changes the owne
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | 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. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
...@@ -2346,27 +2349,29 @@ Synchronously changes the file owner based on the file path and changes the owne ...@@ -2346,27 +2349,29 @@ 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 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 **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | 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.| | 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. | | callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. |
**Return value** **Return value**
| Name | Description | | Type | Description |
| -------------------- | ---------- | | -------------------- | ---------- |
| [Watcher](#watcher7) | Instance for listening for a file change event.| | [Watcher](#watcher7) | Promise used to return the **Watcher** instance.|
**Example** **Example**
```js ```js
fileio.createWatcher(filename, events, function(watcher){ let filename = path +"/test.txt";
// Do something. fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
}); });
``` ```
...@@ -2498,7 +2503,7 @@ Checks whether this file is a regular file. ...@@ -2498,7 +2503,7 @@ Checks whether this file is a regular file.
**Example** **Example**
```js ```js
let isFile = fileio.statSync(fpath).isFile(); let isFile = fileio.statSync(path).isFile();
``` ```
...@@ -2549,13 +2554,19 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy ...@@ -2549,13 +2554,19 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy
stop(): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Example** **Example**
```js ```js
fileio.stop(); let filename = path +"/test.txt";
let watcher = await fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
});
watcher.stop().then(function(){
console.info("Watcher stopped");
});
``` ```
...@@ -2563,7 +2574,7 @@ Asynchronously stops **watcher**. This API uses a promise to return the result. ...@@ -2563,7 +2574,7 @@ Asynchronously stops **watcher**. This API uses a promise to return the result.
stop(callback: AsyncCallback&lt;void&gt;): void 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2574,23 +2585,25 @@ Asynchronously stops **watcher**. This API uses a callback to return the result. ...@@ -2574,23 +2585,25 @@ Asynchronously stops **watcher**. This API uses a callback to return the result.
**Example** **Example**
```js ```js
fileio.stop(function(err){ let filename = path +"/test.txt";
// Do something. let watcher = await fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
}); });
watcher.stop(function(){
console.info("Watcher stopped");
})
``` ```
## Stream
Provides file stream management. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance.
## 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.
### close<sup>7+</sup> ### close<sup>7+</sup>
close(): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2601,11 +2614,11 @@ Asynchronously closes the stream. This API uses a promise to return the result. ...@@ -2601,11 +2614,11 @@ Asynchronously closes the stream. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.close().then(function(){ ss.close().then(function(){
console.info("close fileStream successfully"); console.info("Stream closed");
}).catch(function(err){ }).catch(function(err){
console.info("close fileStream failed with error:"+ err); console.info("Failed to close the file stream. Error:"+ err);
}); });
``` ```
...@@ -2614,7 +2627,7 @@ Asynchronously closes the stream. This API uses a promise to return the result. ...@@ -2614,7 +2627,7 @@ Asynchronously closes the stream. This API uses a promise to return the result.
close(callback: AsyncCallback&lt;void&gt;): void 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2625,9 +2638,9 @@ Asynchronously closes the stream. This API uses a callback to return the result. ...@@ -2625,9 +2638,9 @@ Asynchronously closes the stream. This API uses a callback to return the result.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.close(function (err) { ss.close(function (err) {
// do something // Do something
}); });
``` ```
...@@ -2642,7 +2655,7 @@ Synchronously closes the stream. ...@@ -2642,7 +2655,7 @@ Synchronously closes the stream.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.closeSync(); ss.closeSync();
``` ```
...@@ -2651,7 +2664,7 @@ Synchronously closes the stream. ...@@ -2651,7 +2664,7 @@ Synchronously closes the stream.
flush(): Promise&lt;void&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2662,11 +2675,11 @@ Asynchronously flushes the stream. This API uses a promise to return the result. ...@@ -2662,11 +2675,11 @@ Asynchronously flushes the stream. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flush().then(function (){ ss.flush().then(function (){
console.info("flush successfully"); console.info("Stream flushed");
}).catch(function(err){ }).catch(function(err){
console.info("flush failed with error:"+ err); console.info("Failed to flush the stream. Error:"+ err);
}); });
``` ```
...@@ -2675,7 +2688,7 @@ Asynchronously flushes the stream. This API uses a promise to return the result. ...@@ -2675,7 +2688,7 @@ Asynchronously flushes the stream. This API uses a promise to return the result.
flush(callback: AsyncCallback&lt;void&gt;): void 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2686,9 +2699,9 @@ Asynchronously flushes the stream. This API uses a callback to return the result ...@@ -2686,9 +2699,9 @@ Asynchronously flushes the stream. This API uses a callback to return the result
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flush(function (err) { ss.flush(function (err) {
// do something // Do something
}); });
``` ```
...@@ -2703,7 +2716,7 @@ Synchronously flushes the stream. ...@@ -2703,7 +2716,7 @@ Synchronously flushes the stream.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flushSync(); ss.flushSync();
``` ```
...@@ -2717,7 +2730,7 @@ write(buffer: ArrayBuffer | string, options?: { ...@@ -2717,7 +2730,7 @@ write(buffer: ArrayBuffer | string, options?: {
encoding?: string; encoding?: string;
}): Promise&lt;number&gt; }): 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2730,15 +2743,15 @@ Asynchronously writes data into the stream. This API uses a promise to return th ...@@ -2730,15 +2743,15 @@ Asynchronously writes data into the stream. This API uses a promise to return th
**Return value** **Return value**
| Type | Description | | 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** **Example**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){ 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("Data written to the stream and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("write failed with error:"+ err); console.info("Failed to write data into the stream. Error:"+ err);
}); });
``` ```
...@@ -2752,7 +2765,7 @@ write(buffer: ArrayBuffer | string, options: { ...@@ -2752,7 +2765,7 @@ write(buffer: ArrayBuffer | string, options: {
encoding?: string; encoding?: string;
}, callback: AsyncCallback&lt;number&gt;): void }, 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2765,11 +2778,11 @@ Asynchronously writes data into the stream. This API uses a callback to return t ...@@ -2765,11 +2778,11 @@ Asynchronously writes data into the stream. This API uses a callback to return t
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) { ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) {
if (bytesWritten) { if (bytesWritten) {
// do something // Do something
console.info("write successfully and size is:"+ bytesWritten); console.info("Data written to the stream and size is:"+ bytesWritten);
} }
}); });
``` ```
...@@ -2801,7 +2814,7 @@ Synchronously writes data into the stream. ...@@ -2801,7 +2814,7 @@ Synchronously writes data into the stream.
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(fpath,"r+"); let ss= fileio.createStreamSync(path,"r+");
let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}); let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'});
``` ```
...@@ -2814,7 +2827,7 @@ read(buffer: ArrayBuffer, options?: { ...@@ -2814,7 +2827,7 @@ read(buffer: ArrayBuffer, options?: {
length?: number; length?: number;
}): Promise&lt;ReadOut&gt; }): 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2827,16 +2840,16 @@ Asynchronously reads data from the stream. This API uses a promise to return the ...@@ -2827,16 +2840,16 @@ Asynchronously reads data from the stream. This API uses a promise to return the
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.| | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){ 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))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){ }).catch(function(err){
console.info("read data failed with error:"+ err); console.info("Failed to read data. Error:"+ err);
}); });
``` ```
...@@ -2849,7 +2862,7 @@ read(buffer: ArrayBuffer, options: { ...@@ -2849,7 +2862,7 @@ read(buffer: ArrayBuffer, options: {
length?: number; length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void }, 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2862,10 +2875,10 @@ Asynchronously reads data from the stream. This API uses a callback to return th ...@@ -2862,10 +2875,10 @@ Asynchronously reads data from the stream. This API uses a callback to return th
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) { ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
if (readOut) { if (readOut) {
console.info("read data successfully"); console.info("Read data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
} }
}); });
...@@ -2899,7 +2912,7 @@ Synchronously reads data from the stream. ...@@ -2899,7 +2912,7 @@ Synchronously reads data from the stream.
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5});
``` ```
...@@ -2913,22 +2926,22 @@ Manages directories. Before calling a method of the **Dir** class, use the [open ...@@ -2913,22 +2926,22 @@ Manages directories. Before calling a method of the **Dir** class, use the [open
read(): Promise&lt;Dirent&gt; 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.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | 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** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.read().then(function (dirent){ dir.read().then(function (dirent){
console.log("read successfully:"+JSON.stringify(dirent)); console.log("Read the next directory entry:"+JSON.stringify(dirent));
}).catch(function(err){ }).catch(function(err){
console.info("read failed with error:"+ err); console.info("Failed to read data. Error:"+ err);
}); });
``` ```
...@@ -2937,7 +2950,7 @@ Asynchronously reads the next directory entry. This API uses a promise to return ...@@ -2937,7 +2950,7 @@ Asynchronously reads the next directory entry. This API uses a promise to return
read(callback: AsyncCallback&lt;Dirent&gt;): void 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2951,8 +2964,8 @@ Asynchronously reads the next directory entry. This API uses a callback to retur ...@@ -2951,8 +2964,8 @@ Asynchronously reads the next directory entry. This API uses a callback to retur
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.read(function (err, dirent) { dir.read(function (err, dirent) {
if (dirent) { if (dirent) {
// do something // Do something
console.log("read successfully:"+JSON.stringify(dirent)); console.log("Read the next directory entry:"+JSON.stringify(dirent));
} }
}); });
``` ```
...@@ -2978,6 +2991,40 @@ Synchronously reads the next directory entry. ...@@ -2978,6 +2991,40 @@ Synchronously reads the next directory entry.
``` ```
### close<sup>7+</sup>
close(): Promise&lt;void&gt;
Closes a directory. This API uses a promise to return the result. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Example**
```js
let dir = fileio.opendirSync(path);
dir.close().then(function(err){
console.info("close dir successfully");
});
```
### close<sup>7+</sup>
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
closeSync(): void closeSync(): void
...@@ -3010,7 +3057,7 @@ Provides information about files and directories. Before calling a method of the ...@@ -3010,7 +3057,7 @@ Provides information about files and directories. Before calling a method of the
isBlockDevice(): boolean 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 **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -3070,7 +3117,7 @@ Checks whether a directory entry is a directory. ...@@ -3070,7 +3117,7 @@ Checks whether a directory entry is a directory.
isFIFO(): boolean 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 **System capability**: SystemCapability.FileManagement.File.FileIO
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
>- The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. >- The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**. >- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**.
This module provides service APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files. Provides service APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
## Modules to Import ## Modules to Import
...@@ -18,20 +18,20 @@ getRoot(options? : {dev? : DevInfo}) : Promise&lt;FileInfo[]&gt; ...@@ -18,20 +18,20 @@ getRoot(options? : {dev? : DevInfo}) : Promise&lt;FileInfo[]&gt;
Obtains information about the root album or directory in asynchronous mode. This API uses a promise to return the result. Obtains information about the root album or directory in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| 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.| | 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.|
- Return value **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| Promise&lt;[FileInfo](#fileinfo)[]&gt; | Promise used to return the root album or directory information obtained.| | Promise&lt;[FileInfo](#fileinfo)[]&gt; | Promise used to return the root album or directory information obtained.|
- Example **Example**
```js ```js
filemanager.getRoot().then((fileInfo) => { filemanager.getRoot().then((fileInfo) => {
...@@ -51,25 +51,31 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;) ...@@ -51,25 +51,31 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;)
Obtains information about the root album or directory in asynchronous mode. This API uses a callback to return the result. Obtains information about the root album or directory in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| 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.| | 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 root album or directory information obtained. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the root album or directory information obtained. |
- Example **Example**
```js ```js
filemanager.getRoot((err, fileInfo) => { let options = {
"dev":{
"name":"local"
}
};
filemanager.getRoot(options, (err, fileInfo)=>{
if(Array.isArray(fileInfo)) { if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) { for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo)); console.log("file:"+JSON.stringify(fileInfo));
} }
} }
}); });
``` ```
## filemanager.listFile ## filemanager.listFile
...@@ -78,34 +84,35 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -78,34 +84,35 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
Obtains information about the second-level album or files in asynchronous mode. This API uses a promise to return the result. Obtains information about the second-level album or files in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| path | string | Yes| URI of the directory to query.| | 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**.| | 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.| | 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.|
- Return value
| Type| Description| **Return value**
| --- | -- |
| Promise&lt;FileInfo[]&gt; | Promise used to return the album or file information obtained.|
- Error | Type| Description|
| Error Info| Error Code|Description| | --- | -- |
| -- | --- | -- | | Promise&lt;FileInfo[]&gt; | Promise used to return the album or file information obtained.|
| No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service.|
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example **Error**
| Error Info| Error Code|Description|
| -- | --- | -- |
| No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service.|
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
**Example**
```js ```js
// Obtain all files in the directory. // Obtain all files in the directory.
// Call listFile() and getRoot() to obtain the file URI. // Call listFile() and getRoot() to obtain the file URI.
let media_path = file.uri let media_path = ""
filemanager.listFile(media_path, "file") filemanager.listFile(media_path, "file")
.then((fileInfo) => { .then((fileInfo) => {
if(Array.isArray(fileInfo)) { if(Array.isArray(fileInfo)) {
...@@ -114,7 +121,7 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -114,7 +121,7 @@ Obtains information about the second-level album or files in asynchronous mode.
} }
} }
}).catch((err) => { }).catch((err) => {
console.log(err) console.log("Failed to get file"+err);
}); });
``` ```
...@@ -124,35 +131,52 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -124,35 +131,52 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
Obtains information about the second-level album or files in asynchronous mode. This API uses a callback to return the result. Obtains information about the second-level album or files in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | URI of the directory to query. | | 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**.| | 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.| | 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. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the root album or directory information obtained. |
- Error
| Error Info | Error Code| Description | **Error**
| ------------------------- | ------ | ------------------------- |
| No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service. |
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example | Error Info | Error Code| Description |
| ------------------------- | ------ | ------------------------- |
| No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service. |
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
**Example**
```js ```js
// Call listFile() and getRoot() to obtain the file URI. // Call listFile() and getRoot() to obtain the file path.
let media_path = file.uri let fileInfos = filemanager.getRoot();
filemanager.listFile(media_path, "file", (err, fileInfo) => { let media_path = "";
if(Array.isArray(fileInfo)) { for (let i = 0; i < fileInfos.length; i++) {
for (var i = 0; i < fileInfo.length; i++) { if (fileInfos[i].name == "image_album") {
console.log("file:"+JSON.stringify(fileInfo)); 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("Failed to get file"+err);
}); });
``` ```
...@@ -162,34 +186,35 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P ...@@ -162,34 +186,35 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
Creates a file in the specified path in asynchronous mode. This API uses a promise to return the result. Creates a file in the specified path in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| 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.|
- Parameters **Return value**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| 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.|
- Return value | Type| Description|
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the file created.|
| Type| Description| **Error**
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the file created.|
- Error | Error Info| Error Code|Description|
| Error Info| Error Code|Description| | -- | --- | -- |
| -- | --- | -- | | Operation not permitted | 1 | A file with the same name already exists.|
| Operation not permitted | 1 | A file with the same name already exists.| | No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such file or directory | 2 | The directory or album of the specified URI does not exist.| | No such process | 3 | Failed to obtain the FMS service.|
| No such process | 3 | Failed to obtain the FMS service.| | Not a directory | 20 | The object specified by the URI is not a directory or album.|
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example **Example**
```js ```js
// Create a file. // Create a file.
let media_path = file.uri // Obtain the file URI using listFile() and getRoot(). let media_path = "" // Obtain the file URI using listFile() and getRoot().
let name = "xxx.jpg" // File to be saved. let name = "xxx.jpg" // File to be saved.
filemanager.createFile(media_path, name).then((uri) => { filemanager.createFile(media_path, name).then((uri) => {
// The URI of the file created is returned. // The URI of the file created is returned.
...@@ -205,44 +230,50 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -205,44 +230,50 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
Creates a file in the specified path in asynchronous mode. This API uses a callback to return the result. Creates a file in the specified path in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| filename | string | Yes | Name of the file to create. | | filename | string | Yes | Name of the file to create. |
| path | string | Yes | URI 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.| | 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. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the root album or directory information obtained. |
- Error **Error**
| Error Info | Error Code| Description | | Error Info | Error Code| Description |
| ------------------------- | ------ | ------------------------- | | ------------------------- | ------ | ------------------------- |
| Operation not permitted | 1 | A file with the same name already exists. | | Operation not permitted | 1 | A file with the same name already exists. |
| No such file or directory | 2 | The directory or album of the specified URI does not exist.| | No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service. | | No such process | 3 | Failed to obtain the FMS service. |
| Not a directory | 20 | The object specified by the URI is not a directory or album.| | Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example **Example**
```js ```js
// Create a file. // Create a file.
// Call listFile() and getRoot() to obtain the file URI. // Call listFile() and getRoot() to obtain the file URI.
let media_path = file.uri let media_path = ""
// File to be saved. // File to be saved.
let name = "xxx.jpg" let name = "xxx.jpg"
filemanager.createFile(media_path, name, (err, uri) => { let options = {
// The URI of the file created is returned. "dev":{
console.log("file uri:"+uri); "name":"local"
}
};
filemanager.createFile(media_path, name, options, function(err, uri) {
// The URI of the file created is returned.
console.log("file uri:"+uri);
}); });
``` ```
## FileInfo ## FileInfo
Defines the file information returned by **getRoot()** or **listFile()**. Defines the file information returned by **getRoot()** or **listFile()**.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
### Attributes ### Attributes
...@@ -259,7 +290,7 @@ Defines the file information returned by **getRoot()** or **listFile()**. ...@@ -259,7 +290,7 @@ Defines the file information returned by **getRoot()** or **listFile()**.
Defines the device type. Defines the device type.
**System capability**: SystemCapability.FileManagement.FileManagerService **System capability**: SystemCapability.FileManagement.UserFileService
### Attributes ### Attributes
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册