未验证 提交 24c0dbb3 编写于 作者: O openharmony_ci 提交者: Gitee

!5487 [翻译完成】#I5A38K

Merge pull request !5487 from Annie_wang/PR4664
...@@ -132,6 +132,7 @@ ...@@ -132,6 +132,7 @@
- [@ohos.environment](js-apis-environment.md) - [@ohos.environment](js-apis-environment.md)
- [@ohos.fileio](js-apis-fileio.md) - [@ohos.fileio](js-apis-fileio.md)
- [@ohos.fileManager](js-apis-filemanager.md) - [@ohos.fileManager](js-apis-filemanager.md)
- [@ohos.securityLabel](js-apis-securityLabel.md)
- [@ohos.statfs](js-apis-statfs.md) - [@ohos.statfs](js-apis-statfs.md)
- [@ohos.storageStatistics](js-apis-storage-statistics.md) - [@ohos.storageStatistics](js-apis-storage-statistics.md)
- [@ohos.volumeManager](js-apis-volumemanager.md) - [@ohos.volumeManager](js-apis-volumemanager.md)
......
# 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 common file storage functions. It provides the following JavaScript I/O APIs, including: Provides file storage and management capabilities, including basic file management, file directory management, file information statistics, and stream read and write.
- Basic APIs for file management
- Basic APIs for directory management
- Statistical APIs for obtaining file information
- Stream APIs for reading and writing files
## Modules to Import ## Modules to Import
...@@ -19,22 +14,11 @@ import fileio from '@ohos.fileio'; ...@@ -19,22 +14,11 @@ import fileio from '@ohos.fileio';
## Guidelines ## Guidelines
Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md). 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
Absolute file or directory path = 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 absolute path of the file is as follows: let path = context.getFilesDir();
```js
let path = dir + "/xxx.txt";
```
The file descriptor is as follows:
```js
let fd = fileio.openSync(path);
``` ```
...@@ -42,15 +26,15 @@ let fd = fileio.openSync(path); ...@@ -42,15 +26,15 @@ let fd = fileio.openSync(path);
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 asynchronously.
**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 | Absolute path of the target file.| | path | string | Yes | Application sandbox path of the file.|
**Return value** **Return value**
...@@ -61,7 +45,7 @@ Asynchronously obtains file information. This API uses a promise to return the r ...@@ -61,7 +45,7 @@ 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("getFileInfo succeed:"+ JSON.stringify(stat));
}).catch(function(err){ }).catch(function(err){
console.info("getFileInfo failed with error:"+ err); console.info("getFileInfo failed with error:"+ err);
}); });
...@@ -72,15 +56,15 @@ Asynchronously obtains file information. This API uses a promise to return the r ...@@ -72,15 +56,15 @@ 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 | Absolute 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**
```js ```js
...@@ -99,9 +83,9 @@ Synchronously obtains file information. ...@@ -99,9 +83,9 @@ Synchronously obtains file information.
**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 | Absolute path of the target file.| | path | string | Yes | Application sandbox path of the file.|
**Return value** **Return value**
...@@ -120,24 +104,24 @@ Synchronously obtains file information. ...@@ -120,24 +104,24 @@ 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 asynchronously.
**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 | Absolute path of the directory to open.| | path | string | Yes | Application sandbox path of the directory to open.|
**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("opendir succeed:"+ JSON.stringify(dir));
}).catch(function(err){ }).catch(function(err){
console.info("opendir failed with error:"+ err); console.info("opendir failed with error:"+ err);
}); });
...@@ -148,16 +132,16 @@ Asynchronously opens a directory. This API uses a promise to return the result. ...@@ -148,16 +132,16 @@ 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
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | -------------- | | -------- | -------------------------------- | ---- | ------------------------------ |
| path | string | Yes | Absolute path of the directory to open. | | path | string | Yes | Application sandbox path of the directory to open.|
| callback | AsyncCallback&lt;[Dir](#dir)&gt; | Yes | Callback invoked when the directory is open asynchronously.| | callback | AsyncCallback&lt;[Dir](#dir)&gt; | Yes | Callback invoked when the directory is open asynchronously. |
**Example** **Example**
```js ```js
...@@ -179,9 +163,9 @@ Synchronously opens a directory. ...@@ -179,9 +163,9 @@ Synchronously opens a directory.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------- | | ------ | ------ | ---- | ------------------------------ |
| path | string | Yes | Absolute path of the directory to open.| | path | string | Yes | Application sandbox path of the directory to open.|
**Return value** **Return value**
| Type | Description | | Type | Description |
...@@ -200,26 +184,26 @@ Synchronously opens a directory. ...@@ -200,26 +184,26 @@ 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 asynchronously.
**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 | Absolute 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 which returns no value.|
**Example** **Example**
```js ```js
fileio.access(path).then(function() { fileio.access(path).then(function() {
console.info("access successfully"); console.info("access succeed");
}).catch(function(err){ }).catch(function(err){
console.info("access failed with error:"+ err); console.info("access failed with error:"+ err);
}); });
...@@ -230,16 +214,16 @@ Asynchronously checks whether the current process can access a file. This API us ...@@ -230,16 +214,16 @@ 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 | Absolute 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. |
**Example** **Example**
```js ```js
...@@ -258,10 +242,10 @@ Synchronously checks whether the current process can access the specified file. ...@@ -258,10 +242,10 @@ Synchronously checks whether the current process can access the specified file.
**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 | Absolute 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**
```js ```js
...@@ -277,7 +261,7 @@ Synchronously checks whether the current process can access the specified file. ...@@ -277,7 +261,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -289,13 +273,13 @@ Asynchronously closes a file. This API uses a promise to return the result. ...@@ -289,13 +273,13 @@ 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 which 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("close file succeed");
}).catch(function(err){ }).catch(function(err){
console.info("close file failed with error:"+ err); console.info("close file failed with error:"+ err);
}); });
...@@ -306,7 +290,7 @@ Asynchronously closes a file. This API uses a promise to return the result. ...@@ -306,7 +290,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
...@@ -348,19 +332,19 @@ Synchronously closes a file. ...@@ -348,19 +332,19 @@ 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 asynchronously.
**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 which returns no value.|
**Example** **Example**
```js ```js
fileio.close().then(function(){ fileio.close().then(function(){
console.info("close file stream successfully"); console.info("close file stream succeed");
}).catch(function(err){ }).catch(function(err){
console.info("close file stream failed with error:"+ err); console.info("close file stream failed with error:"+ err);
}); });
...@@ -371,7 +355,7 @@ Asynchronously closes the stream. This API uses a promise to return the result. ...@@ -371,7 +355,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
...@@ -392,7 +376,7 @@ Asynchronously closes the stream. This API uses a callback to return the result. ...@@ -392,7 +376,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -406,12 +390,12 @@ Asynchronously copies a file. This API uses a promise to return the result. ...@@ -406,12 +390,12 @@ 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 which 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("copyFile succeed");
}).catch(function(err){ }).catch(function(err){
console.info("copyFile failed with error:"+ err); console.info("copyFile failed with error:"+ err);
}); });
...@@ -422,7 +406,7 @@ Asynchronously copies a file. This API uses a promise to return the result. ...@@ -422,7 +406,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
...@@ -467,25 +451,25 @@ Synchronously copies a file. ...@@ -467,25 +451,25 @@ 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 asynchronously.
**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 | Absolute 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 which returns no value.|
**Example** **Example**
```js ```js
fileio.mkdir(path).then(function() { fileio.mkdir(path).then(function() {
console.info("mkdir successfully"); console.info("mkdir succeed");
}).catch(function (error){ }).catch(function (error){
console.info("mkdir failed with error:"+ error); console.info("mkdir failed with error:"+ error);
}); });
...@@ -496,21 +480,21 @@ Asynchronously creates a directory. This API uses a promise to return the result ...@@ -496,21 +480,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 | Absolute 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("mkdir succeed");
}); });
``` ```
...@@ -524,10 +508,10 @@ Synchronously creates a directory. ...@@ -524,10 +508,10 @@ Synchronously creates a directory.
**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 | Absolute 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**
```js ```js
...@@ -539,26 +523,26 @@ Synchronously creates a directory. ...@@ -539,26 +523,26 @@ 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 asynchronously.
**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 | Absolute 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** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | 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("open file succeed");
}).catch(function(error){ }).catch(function(error){
console.info("open file failed with error:"+ err); console.info("open file failed with error:"+ err);
}); });
...@@ -569,17 +553,17 @@ Asynchronously opens a file. This API uses a promise to return the result. ...@@ -569,17 +553,17 @@ 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 | Absolute 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** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | 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. |
**Example** **Example**
```js ```js
...@@ -598,11 +582,11 @@ Synchronously opens a file. ...@@ -598,11 +582,11 @@ Synchronously opens a file.
**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 | Absolute 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** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**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 |
...@@ -623,7 +607,7 @@ read(fd: number, buffer: ArrayBuffer, options?: { ...@@ -623,7 +607,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -638,14 +622,14 @@ Asynchronously reads data from a file. This API uses a promise to return the res ...@@ -638,14 +622,14 @@ 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 succeed");
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(error){
console.info("read file data failed with error:"+ error); console.info("read file data failed with error:"+ error);
...@@ -661,7 +645,7 @@ read(fd: number, buffer: ArrayBuffer, options: { ...@@ -661,7 +645,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
...@@ -679,7 +663,7 @@ Asynchronously reads data from a file. This API uses a callback to return the re ...@@ -679,7 +663,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 succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
} }
}); });
...@@ -722,24 +706,24 @@ Synchronously reads data from a file. ...@@ -722,24 +706,24 @@ 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 asynchronously.
**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 | Absolute 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 which returns no value.|
**Example** **Example**
```js ```js
fileio.rmdir(path).then(function() { fileio.rmdir(path).then(function() {
console.info("rmdir successfully"); console.info("rmdir succeed");
}).catch(function(err){ }).catch(function(err){
console.info("rmdir failed with error:"+ err); console.info("rmdir failed with error:"+ err);
}); });
...@@ -750,21 +734,21 @@ Asynchronously deletes a directory. This API uses a promise to return the result ...@@ -750,21 +734,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 | Absolute 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("rmdir succeed");
}); });
``` ```
...@@ -778,9 +762,9 @@ Synchronously deletes a directory. ...@@ -778,9 +762,9 @@ Synchronously deletes a directory.
**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 | Absolute path of the directory to delete.| | path | string | Yes | Application sandbox path of the directory.|
**Example** **Example**
```js ```js
...@@ -792,24 +776,24 @@ Synchronously deletes a directory. ...@@ -792,24 +776,24 @@ 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 asynchronously.
**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 | Absolute 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 which returns no value.|
**Example** **Example**
```js ```js
fileio.unlink(path).then(function(){ fileio.unlink(path).then(function(){
console.info("remove file successfully"); console.info("remove file succeed");
}).catch(function(error){ }).catch(function(error){
console.info("remove file failed with error:"+ error); console.info("remove file failed with error:"+ error);
}); });
...@@ -820,20 +804,20 @@ Asynchronously deletes a file. This API uses a promise to return the result. ...@@ -820,20 +804,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 | Absolute 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("remove file succeed");
}); });
``` ```
...@@ -847,9 +831,9 @@ Synchronously deletes a file. ...@@ -847,9 +831,9 @@ Synchronously deletes a file.
**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 | Absolute path of the file to delete.| | path | string | Yes | Application sandbox path of the file.|
**Example** **Example**
```js ```js
...@@ -866,7 +850,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: { ...@@ -866,7 +850,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -880,13 +864,13 @@ Asynchronously writes data into a file. This API uses a promise to return the re ...@@ -880,13 +864,13 @@ 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(fpath, 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("write data to file succeed and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("write data to file failed with error:"+ err); console.info("write data to file failed with error:"+ err);
}); });
...@@ -902,7 +886,7 @@ write(fd: number, buffer: ArrayBuffer | string, options: { ...@@ -902,7 +886,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
...@@ -919,7 +903,7 @@ Asynchronously writes data into a file. This API uses a callback to return the r ...@@ -919,7 +903,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("write data to file succeed and size is:"+ bytesWritten);
} }
}); });
``` ```
...@@ -961,25 +945,25 @@ Synchronously writes data into a file. ...@@ -961,25 +945,25 @@ 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 asynchronously.
**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 | Absolute 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("calculate file hash succeed:"+ str);
}).catch(function(error){ }).catch(function(error){
console.info("calculate file hash failed with error:"+ err); console.info("calculate file hash failed with error:"+ err);
}); });
...@@ -990,22 +974,22 @@ Asynchronously calculates the hash value of a file. This API uses a promise to r ...@@ -990,22 +974,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 | Absolute 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(fpath, "sha256", function(err, hashStr) {
if (hashStr) { if (hashStr) {
console.info("calculate file hash successfully:"+ hashStr); console.info("calculate file hash succeed:"+ hashStr);
} }
}); });
``` ```
...@@ -1015,25 +999,25 @@ Asynchronously calculates the hash value of a file. This API uses a callback to ...@@ -1015,25 +999,25 @@ 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 asynchronously.
**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 | Absolute 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 which 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("chmod succeed");
}).catch(function(err){ }).catch(function(err){
console.info("chmod failed with error:"+ err); console.info("chmod failed with error:"+ err);
}); });
...@@ -1044,16 +1028,16 @@ Asynchronously changes the file permissions based on its path. This API uses a p ...@@ -1044,16 +1028,16 @@ 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 | Absolute 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. |
**Example** **Example**
```js ```js
...@@ -1067,15 +1051,15 @@ Asynchronously changes the file permissions based on its path. This API uses a c ...@@ -1067,15 +1051,15 @@ 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 | Absolute 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
...@@ -1087,7 +1071,7 @@ Synchronously changes the file permissions based on its path. ...@@ -1087,7 +1071,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 status information based on the file descriptor. This API uses a promise to return the result. Obtains file information based on the file descriptor. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1099,12 +1083,12 @@ Asynchronously obtains file status information based on the file descriptor. Thi ...@@ -1099,12 +1083,12 @@ Asynchronously obtains file status information based on the file descriptor. Thi
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file status 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("fstat succeed:"+ JSON.stringify(stat));
}).catch(function(err){ }).catch(function(err){
console.info("fstat failed with error:"+ err); console.info("fstat failed with error:"+ err);
}); });
...@@ -1115,7 +1099,7 @@ Asynchronously obtains file status information based on the file descriptor. Thi ...@@ -1115,7 +1099,7 @@ Asynchronously obtains file status information based on the file descriptor. Thi
fstat(fd: number, callback: AsyncCallback&lt;Stat&gt;): void fstat(fd: number, callback: AsyncCallback&lt;Stat&gt;): void
Asynchronously obtains file status 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
...@@ -1123,7 +1107,7 @@ Asynchronously obtains file status information based on the file descriptor. Thi ...@@ -1123,7 +1107,7 @@ Asynchronously obtains file status information based on the file descriptor. Thi
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------- | ---- | ---------------- | | -------- | ---------------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked when the file status information is obtained asynchronously.| | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
**Example** **Example**
```js ```js
...@@ -1138,7 +1122,7 @@ Asynchronously obtains file status information based on the file descriptor. Thi ...@@ -1138,7 +1122,7 @@ Asynchronously obtains file status information based on the file descriptor. Thi
fstatSync(fd: number): Stat fstatSync(fd: number): Stat
Synchronously obtains file status information based on the file descriptor. Synchronously obtains file information based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1163,7 +1147,7 @@ Synchronously obtains file status information based on the file descriptor. ...@@ -1163,7 +1147,7 @@ Synchronously obtains file status 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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1171,18 +1155,18 @@ Asynchronously truncates a file based on the file descriptor. This API uses a pr ...@@ -1171,18 +1155,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 which 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("truncate file succeed");
}).catch(function(err){ }).catch(function(err){
console.info("Failed to truncate the file. Error:"+ err); console.info("Failed to truncate the file. Error:"+ err);
}); });
...@@ -1193,7 +1177,7 @@ Asynchronously truncates a file based on the file descriptor. This API uses a pr ...@@ -1193,7 +1177,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
...@@ -1202,7 +1186,7 @@ Asynchronously truncates a file based on the file descriptor. This API uses a ca ...@@ -1202,7 +1186,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 which returns no value. |
**Example** **Example**
```js ```js
...@@ -1236,25 +1220,25 @@ Synchronously truncates a file based on the file descriptor. ...@@ -1236,25 +1220,25 @@ 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 asynchronously.
**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 | Absolute 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 which 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("truncate file succeed");
}).catch(function(err){ }).catch(function(err){
console.info("Failed to truncate the file. Error:"+ err); console.info("Failed to truncate the file. Error:"+ err);
}); });
...@@ -1265,16 +1249,16 @@ Asynchronously truncates a file based on its path. This API uses a promise to re ...@@ -1265,16 +1249,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 | Absolute path of the file to truncate. | | path | string | Yes | Application sandbox path of the file to be truncated. |
| 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 invoked, which returns no value. |
**Example** **Example**
```js ```js
...@@ -1293,10 +1277,10 @@ Synchronously truncates a file based on the file path. ...@@ -1293,10 +1277,10 @@ Synchronously truncates a file based on the file path.
**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 | Absolute path of the file to 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**
```js ```js
...@@ -1312,25 +1296,25 @@ readText(filePath: string, options?: { ...@@ -1312,25 +1296,25 @@ 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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Absolute 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** (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**
| 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("readText succeed:"+ str);
}).catch(function(err){ }).catch(function(err){
console.info("readText failed with error:"+ err); console.info("readText failed with error:"+ err);
}); });
...@@ -1345,16 +1329,16 @@ readText(filePath: string, options: { ...@@ -1345,16 +1329,16 @@ 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
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------------------- | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Absolute 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
...@@ -1377,10 +1361,10 @@ Synchronously reads the text of a file. ...@@ -1377,10 +1361,10 @@ Synchronously reads the text of a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Absolute 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** (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**
| Type | Description | | Type | Description |
...@@ -1397,24 +1381,24 @@ Synchronously reads the text of a file. ...@@ -1397,24 +1381,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 status information. This API uses a promise to return the result. Obtains link information. This API uses a promise to return the result asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------------- | | ------ | ------ | ---- | -------------------------------------- |
| path | string | Yes | Absolute path of the target file, pointing to the link status.| | 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 status 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("get link status succeed:"+ number);
}).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);
}); });
...@@ -1425,15 +1409,15 @@ Asynchronously obtains link status information. This API uses a promise to retur ...@@ -1425,15 +1409,15 @@ Asynchronously obtains link status information. This API uses a promise to retur
lstat(path:string, callback:AsyncCallback&lt;Stat&gt;): void lstat(path:string, callback:AsyncCallback&lt;Stat&gt;): void
Asynchronously obtains link status 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 | Absolute path of the target file, pointing to the link status.| | path | string | Yes | Application sandbox path of the target file.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked when the link status information is obtained asynchronously. | | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback used to return the link information obtained. |
**Example** **Example**
```js ```js
...@@ -1447,19 +1431,19 @@ Asynchronously obtains link status information. This API uses a callback to retu ...@@ -1447,19 +1431,19 @@ Asynchronously obtains link status information. This API uses a callback to retu
lstatSync(path:string): Stat lstatSync(path:string): Stat
Synchronously obtains link status information. Synchronously obtains the link information.
**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 | Absolute path of the target file, pointing to the link status.| | path | string | Yes | Application sandbox path of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | Link status obtained.| | [Stat](#stat) | Link information obtained.|
**Example** **Example**
```js ```js
...@@ -1475,7 +1459,7 @@ read(buffer: ArrayBuffer, options?: { ...@@ -1475,7 +1459,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1488,12 +1472,12 @@ Asynchronously reads data from a file. This API uses a promise to return the res ...@@ -1488,12 +1472,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 succeed");
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);
...@@ -1509,7 +1493,7 @@ read(buffer: ArrayBuffer, options: { ...@@ -1509,7 +1493,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
...@@ -1525,7 +1509,7 @@ Asynchronously reads data from a file. This API uses a callback to return the re ...@@ -1525,7 +1509,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 succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
} }
}); });
...@@ -1536,25 +1520,25 @@ Asynchronously reads data from a file. This API uses a callback to return the re ...@@ -1536,25 +1520,25 @@ 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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------------------ | | ------- | ------ | ---- | ---------------------------- |
| oldPath | string | Yes | Absolute path of the file to rename.| | oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Absolute path of the file renamed. | | newPath | String | Yes | Application sandbox path of the file renamed. |
**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 which 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("rename succeed");
}).catch(function(err){ }).catch(function(err){
console.info("rename failed with error:"+ err); console.info("rename failed with error:"+ err);
}); });
...@@ -1565,16 +1549,16 @@ Asynchronously renames a file. This API uses a promise to return the result. ...@@ -1565,16 +1549,16 @@ 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
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------- | | -------- | ------------------------- | ---- | ---------------------------- |
| oldPath | string | Yes | Absolute path of the file to rename. | | oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Absolute 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**
```js ```js
...@@ -1592,10 +1576,10 @@ Synchronously renames a file. ...@@ -1592,10 +1576,10 @@ Synchronously renames a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------ | | ------- | ------ | ---- | ---------------------------- |
| oldPath | string | Yes | Absolute path of the file to rename.| | oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Absolute path of the file renamed. | | newPath | String | Yes | Application sandbox path of the file renamed. |
**Example** **Example**
```js ```js
...@@ -1607,24 +1591,24 @@ Synchronously renames a file. ...@@ -1607,24 +1591,24 @@ 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 asynchronously.
**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 which returns no value.|
**Example** **Example**
```js ```js
fileio.fsync(fd).then(function(){ fileio.fsync(fd).then(function(){
console.info("sync data successfully"); console.info("sync data succeed");
}).catch(function(err){ }).catch(function(err){
console.info("sync data failed with error:"+ err); console.info("sync data failed with error:"+ err);
}); });
...@@ -1635,14 +1619,14 @@ Asynchronously synchronizes a file. This API uses a promise to return the result ...@@ -1635,14 +1619,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**
...@@ -1657,14 +1641,14 @@ Asynchronously synchronizes a file. This API uses a callback to return the resul ...@@ -1657,14 +1641,14 @@ 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
...@@ -1676,7 +1660,7 @@ Synchronizes a file in synchronous mode. ...@@ -1676,7 +1660,7 @@ 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 asynchronously. **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
...@@ -1688,12 +1672,12 @@ Asynchronously synchronizes data in a file. This API uses a promise to return th ...@@ -1688,12 +1672,12 @@ Asynchronously synchronizes data in a file. This API uses a promise to return th
**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 which 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("sync data succeed");
}).catch(function(err){ }).catch(function(err){
console.info("sync data failed with error:"+ err); console.info("sync data failed with error:"+ err);
}); });
...@@ -1704,7 +1688,7 @@ Asynchronously synchronizes data in a file. This API uses a promise to return th ...@@ -1704,7 +1688,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
...@@ -1745,25 +1729,25 @@ Synchronizes data in a file in synchronous mode. ...@@ -1745,25 +1729,25 @@ 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 asynchronously.
**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 | Absolute path of the symbolic link. | | target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Absolute 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 which 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("symlink succeed");
}).catch(function(err){ }).catch(function(err){
console.info("symlink failed with error:"+ err); console.info("symlink failed with error:"+ err);
}); });
...@@ -1774,16 +1758,16 @@ Asynchronously creates a symbolic link based on a path. This API uses a promise ...@@ -1774,16 +1758,16 @@ 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 | Absolute path of the symbolic link. | | target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Absolute 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**
```js ```js
...@@ -1802,10 +1786,10 @@ Synchronously creates a symbolic link based on a specified path. ...@@ -1802,10 +1786,10 @@ Synchronously creates a symbolic link based on a specified path.
**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 | Absolute path of the symbolic link. | | target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Absolute path of 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
...@@ -1817,27 +1801,27 @@ Synchronously creates a symbolic link based on a specified path. ...@@ -1817,27 +1801,27 @@ 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 asynchronously.
**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 | Absolute 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 which 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("chown succeed");
}).catch(function(err){ }).catch(function(err){
console.info("chown failed with error:"+ err); console.info("chown failed with error:"+ err);
}); });
...@@ -1848,17 +1832,17 @@ Asynchronously changes the file owner based on its path. This API uses a promise ...@@ -1848,17 +1832,17 @@ 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 | Absolute 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
...@@ -1878,11 +1862,11 @@ Synchronously changes the file owner based on its path. ...@@ -1878,11 +1862,11 @@ Synchronously changes the file owner based on its path.
**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 | Absolute 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
...@@ -1895,7 +1879,7 @@ Synchronously changes the file owner based on its path. ...@@ -1895,7 +1879,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1905,14 +1889,14 @@ Asynchronously creates a temporary directory. This API uses a promise to return ...@@ -1905,14 +1889,14 @@ 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("mkdtemp succeed:"+ path);
}).catch(function(err){ }).catch(function(err){
console.info("mkdtemp failed with error:"+ err); console.info("mkdtemp failed with error:"+ err);
}); });
...@@ -1923,7 +1907,7 @@ Asynchronously creates a temporary directory. This API uses a promise to return ...@@ -1923,7 +1907,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
...@@ -1955,7 +1939,7 @@ Synchronously creates a temporary directory. ...@@ -1955,7 +1939,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.|
...@@ -1969,7 +1953,7 @@ Synchronously creates a temporary directory. ...@@ -1969,7 +1953,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1980,14 +1964,14 @@ Asynchronously changes the file permissions based on the file descriptor. This A ...@@ -1980,14 +1964,14 @@ 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 which 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("chmod succeed");
}).catch(function(err){ }).catch(function(err){
console.info("chmod failed with error:"+ err); console.info("chmod failed with error:"+ err);
}); });
...@@ -1998,7 +1982,7 @@ Asynchronously changes the file permissions based on the file descriptor. This A ...@@ -1998,7 +1982,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
...@@ -2041,15 +2025,15 @@ Synchronously changes the file permissions based on the file descriptor. ...@@ -2041,15 +2025,15 @@ 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 asynchronously.
**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 | Absolute 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**
| Type | Description | | Type | Description |
...@@ -2059,7 +2043,7 @@ Asynchronously opens a stream based on the file path. This API uses a promise to ...@@ -2059,7 +2043,7 @@ 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("createStream succeed");
}).catch(function(err){ }).catch(function(err){
console.info("createStream failed with error:"+ err); console.info("createStream failed with error:"+ err);
}); });
...@@ -2070,16 +2054,16 @@ Asynchronously opens a stream based on the file path. This API uses a promise to ...@@ -2070,16 +2054,16 @@ 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 | Absolute 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
...@@ -2098,13 +2082,13 @@ Synchronously opens a stream based on the file path. ...@@ -2098,13 +2082,13 @@ Synchronously opens a stream based on the file path.
**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 | Absolute 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.|
...@@ -2118,7 +2102,7 @@ Synchronously opens a stream based on the file path. ...@@ -2118,7 +2102,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2129,14 +2113,14 @@ Asynchronously opens a stream based on the file descriptor. This API uses a prom ...@@ -2129,14 +2113,14 @@ 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){ fileio.fdopenStream(fd, mode).then(function(stream){
console.info("openStream successfully"); console.info("openStream succeed");
}).catch(function(err){ }).catch(function(err){
console.info("openStream failed with error:"+ err); console.info("openStream failed with error:"+ err);
}); });
...@@ -2147,7 +2131,7 @@ Asynchronously opens a stream based on the file descriptor. This API uses a prom ...@@ -2147,7 +2131,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
...@@ -2195,7 +2179,7 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2195,7 +2179,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2209,13 +2193,13 @@ Asynchronously changes the file owner based on the file descriptor. This API use ...@@ -2209,13 +2193,13 @@ 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 which 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("chown succeed");
}).catch(function(err){ }).catch(function(err){
console.info("chown failed with error:"+ err); console.info("chown failed with error:"+ err);
}); });
...@@ -2226,7 +2210,7 @@ Asynchronously changes the file owner based on the file descriptor. This API use ...@@ -2226,7 +2210,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
...@@ -2273,27 +2257,27 @@ Synchronously changes the file owner based on the file descriptor. ...@@ -2273,27 +2257,27 @@ 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 asynchronously.
**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 | Absolute 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 which 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("chown succeed");
}).catch(function(err){ }).catch(function(err){
console.info("chown failed with error:"+ err); console.info("chown failed with error:"+ err);
}); });
...@@ -2304,17 +2288,17 @@ Asynchronously changes the file owner based on the file path, changes the owner ...@@ -2304,17 +2288,17 @@ 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 | Absolute 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
...@@ -2334,11 +2318,11 @@ Synchronously changes the file owner based on the file path and changes the owne ...@@ -2334,11 +2318,11 @@ Synchronously changes the file owner based on the file path and changes the owne
**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 | Absolute 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
...@@ -2351,21 +2335,21 @@ Synchronously changes the file owner based on the file path and changes the owne ...@@ -2351,21 +2335,21 @@ Synchronously changes the file owner based on the file path and changes the owne
createWatcher(filename: string, events: number, callback: AsyncCallback&lt;number&gt;): Watcher 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 | Absolute 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
...@@ -2554,7 +2538,7 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy ...@@ -2554,7 +2538,7 @@ 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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2568,7 +2552,7 @@ Asynchronously stops **watcher**. This API uses a promise to return the result. ...@@ -2568,7 +2552,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
...@@ -2585,17 +2569,16 @@ Asynchronously stops **watcher**. This API uses a callback to return the result. ...@@ -2585,17 +2569,16 @@ Asynchronously stops **watcher**. This API uses a callback to return the result.
``` ```
## Stream<sup>7+</sup> ## Stream<sup>7+</sup>
File stream. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance. Provides file stream management. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance.
### close<sup>7+</sup> ### close<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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2608,7 +2591,7 @@ Asynchronously closes the stream. This API uses a promise to return the result. ...@@ -2608,7 +2591,7 @@ Asynchronously closes the stream. This API uses a promise to return the result.
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path);
ss.close().then(function(){ ss.close().then(function(){
console.info("close fileStream successfully"); console.info("close fileStream succeed");
}).catch(function(err){ }).catch(function(err){
console.info("close fileStream failed with error:"+ err); console.info("close fileStream failed with error:"+ err);
}); });
...@@ -2619,7 +2602,7 @@ Asynchronously closes the stream. This API uses a promise to return the result. ...@@ -2619,7 +2602,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
...@@ -2656,7 +2639,7 @@ Synchronously closes the stream. ...@@ -2656,7 +2639,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2669,7 +2652,7 @@ Asynchronously flushes the stream. This API uses a promise to return the result. ...@@ -2669,7 +2652,7 @@ Asynchronously flushes the stream. This API uses a promise to return the result.
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path);
ss.flush().then(function (){ ss.flush().then(function (){
console.info("flush successfully"); console.info("flush succeed");
}).catch(function(err){ }).catch(function(err){
console.info("flush failed with error:"+ err); console.info("flush failed with error:"+ err);
}); });
...@@ -2680,7 +2663,7 @@ Asynchronously flushes the stream. This API uses a promise to return the result. ...@@ -2680,7 +2663,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
...@@ -2693,7 +2676,7 @@ Asynchronously flushes the stream. This API uses a callback to return the result ...@@ -2693,7 +2676,7 @@ Asynchronously flushes the stream. This API uses a callback to return the result
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path);
ss.flush(function (err) { ss.flush(function (err) {
// do something // Do something
}); });
``` ```
...@@ -2722,7 +2705,7 @@ write(buffer: ArrayBuffer | string, options?: { ...@@ -2722,7 +2705,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2735,13 +2718,13 @@ Asynchronously writes data into the stream. This API uses a promise to return th ...@@ -2735,13 +2718,13 @@ 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(fpath, "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("write succeed and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("write failed with error:"+ err); console.info("write failed with error:"+ err);
}); });
...@@ -2757,7 +2740,7 @@ write(buffer: ArrayBuffer | string, options: { ...@@ -2757,7 +2740,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
...@@ -2773,8 +2756,8 @@ Asynchronously writes data into the stream. This API uses a callback to return t ...@@ -2773,8 +2756,8 @@ Asynchronously writes data into the stream. This API uses a callback to return t
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(fpath, "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("write succeed and size is:"+ bytesWritten);
} }
}); });
``` ```
...@@ -2819,7 +2802,7 @@ read(buffer: ArrayBuffer, options?: { ...@@ -2819,7 +2802,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 asynchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -2832,13 +2815,13 @@ Asynchronously reads data from the stream. This API uses a promise to return the ...@@ -2832,13 +2815,13 @@ 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(fpath, "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 succeed");
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("read data failed with error:"+ err);
...@@ -2854,7 +2837,7 @@ read(buffer: ArrayBuffer, options: { ...@@ -2854,7 +2837,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
...@@ -2870,7 +2853,7 @@ Asynchronously reads data from the stream. This API uses a callback to return th ...@@ -2870,7 +2853,7 @@ Asynchronously reads data from the stream. This API uses a callback to return th
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(fpath, "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 succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
} }
}); });
...@@ -2918,20 +2901,20 @@ Manages directories. Before calling a method of the **Dir** class, use the [open ...@@ -2918,20 +2901,20 @@ 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 asynchronously.
**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 succeed:"+JSON.stringify(dirent));
}).catch(function(err){ }).catch(function(err){
console.info("read failed with error:"+ err); console.info("read failed with error:"+ err);
}); });
...@@ -2942,7 +2925,7 @@ Asynchronously reads the next directory entry. This API uses a promise to return ...@@ -2942,7 +2925,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
...@@ -2956,8 +2939,8 @@ Asynchronously reads the next directory entry. This API uses a callback to retur ...@@ -2956,8 +2939,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 succeed:"+JSON.stringify(dirent));
} }
}); });
``` ```
...@@ -3015,7 +2998,7 @@ Provides information about files and directories. Before calling a method of the ...@@ -3015,7 +2998,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
...@@ -3075,7 +3058,7 @@ Checks whether a directory entry is a directory. ...@@ -3075,7 +3058,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
......
# Security Label
> **NOTE**<br/>
> 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.
Manages file data security levels, including obtaining and setting file data security levels.
## Modules to Import
```js
import securityLabel from '@ohos.securityLabel';
```
## Usage
Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Application sandbox path of a file or directory = Application directory + File name or directory name
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the application sandbox path of the file is as follows:
```js
let path = dir + "/xxx.txt";
```
The file descriptor is as follows:
```js
let fd = fileio.openSync(path, 0o102, 0o666);
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string):Promise&lt;void&gt;
Sets the security label for a file in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| dataLevel | string | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
**Return value**
| Type | Description |
| ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value will be returned.|
**Example**
```js
securityLabel.setSecurityLabel(path, dataLevel).then(function(){
console.info("setSecurityLabel successfully");
}).catch(function(error){
console.info("setSecurityLabel failed with error:" + error);
});
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback&lt;void&gt;):void
Sets the security label for a file in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| dataLevel | string | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example**
```js
securityLabel.setSecurityLabel(path, dataLevel, function(error){
console.info("setSecurityLabel:" + JSON.stringify(error));
});
```
## securityLabel.setSecurityLabelSync
setSecurityLabelSync(path:string, dataLevel:string):void
Sets the security label for a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| dataLevel | string | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
**Example**
```js
securityLabel.setSecurityLabelSync(path, dataLevel);
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string):Promise&lt;string&gt;
Obtains the security label of a file in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------- |
| path | string | Yes | File path.|
**Return value**
| Type | Description |
| --------------------- | ------------ |
| Promise&lt;string&gt; | Promise used to return the security label obtained.|
**Example**
```js
securityLabel.getSecurityLabel(path).then(function(dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel);
}).catch(function(error){
console.log("getSecurityLabel failed with error:" + error);
});
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
Obtains the security label of a file in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------------- |
| path | string | Yes | File path. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the security label obtained.|
**Example**
```js
securityLabel.getSecurityLabel(function(error, dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel);
});
```
## securityLabel.getSecurityLabelSync
getSecurityLabelSync(path:string):string
Obtains the security label of a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------- |
| path | string | Yes | File path.|
**Return value**
| Type | Description |
| ------ | ------------ |
| string | Security label obtained.|
**Example**
```js
let result = securityLabel.getSecurityLabelSync(path);
console.log("getSecurityLabel successfully:" + result);
```
# statfs # statfs
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Obtains file system information, including the total number of bytes and the number of idle bytes of the file system.
## Modules to Import ## Modules to Import
```js ```js
import statfs from '@ohos.statfs'; import statfs from '@ohos.statfs';
``` ```
## Guidelines
Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Absolute file or directory path = Application directory + File name or directory name
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the absolute path of the file is as follows:
```js
let path = dir + "xxx.txt";
```
## statfs.getFreeBytes ## statfs.getFreeBytes
getFreeBytes(path:string):Promise&lt;number&gt; getFreeBytes(path:string):Promise&lt;number&gt;
Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a promise to return the result. Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -56,7 +45,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -56,7 +45,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
getFreeBytes(path:string, callback:AsyncCallback&lt;number&gt;): void getFreeBytes(path:string, callback:AsyncCallback&lt;number&gt;): void
Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a callback to return the result. Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -70,8 +59,12 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -70,8 +59,12 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
- Example - Example
```js ```js
statfs.getFreeBytes(path, function(err, number){ import featureAbility from '@ohos.ability.featureAbility';
console.info("getFreeBytes callback successfully:"+ number); let context = featureAbility.getContext();
context.getFilesDir().then(function (path) {
statfs.getFreeBytes(path, function(err, number){
console.info("getFreeBytes callback successfully:"+ number);
});
}); });
``` ```
...@@ -79,7 +72,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -79,7 +72,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
getTotalBytes(path: string): Promise&lt;number&gt; getTotalBytes(path: string): Promise&lt;number&gt;
Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a promise to return the result. Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -110,7 +103,7 @@ Obtains the total number of bytes of the specified file system in asynchronous m ...@@ -110,7 +103,7 @@ Obtains the total number of bytes of the specified file system in asynchronous m
getTotalBytes(path: string, callback: AsyncCallback&lt;number&gt;): void getTotalBytes(path: string, callback: AsyncCallback&lt;number&gt;): void
Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a callback to return the result. Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -124,7 +117,11 @@ Obtains the total number of bytes of the specified file system in asynchronous m ...@@ -124,7 +117,11 @@ Obtains the total number of bytes of the specified file system in asynchronous m
- Example - Example
```js ```js
statfs.getTotalBytes(path, function(err, number){ import featureAbility from '@ohos.ability.featureAbility';
console.info("getTotalBytes callback successfully:"+ number); let context = featureAbility.getContext();
context.getFilesDir().then(function (path) {
statfs.getTotalBytes(path, function(err, number){
console.info("getTotalBytes callback successfully:"+ number);
});
}); });
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册