提交 cf401841 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 0337b2b7
......@@ -248,7 +248,7 @@
- [@ohos.file.storageStatistics (Application Storage Statistics)](js-apis-file-storage-statistics.md)
- [@ohos.file.volumeManager (Volume Management)](js-apis-file-volumemanager.md)
- [@ohos.filemanagement.userFileManager (User Data Management)](js-apis-userFileManager.md)
- [@ohos.fileShare (File Sharing)](js-apis-fileShare.md)
- [@ohos.fileshare (File Sharing)](js-apis-fileShare.md)
- Telephony Service
- [@ohos.contact (Contacts)](js-apis-contact.md)
......
......@@ -3,10 +3,8 @@
The **cloudSyncManager** module provides APIs for changing the cloud and device service status and notifying the data changes.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import
......@@ -36,6 +34,15 @@ Changes the device-cloud file synchronization switch for an application. This AP
| --------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
**Example**
```js
......@@ -65,6 +72,15 @@ Changes the device-cloud file synchronization switch for an application. This AP
| status | boolean | Yes | State of the cloud-device file synchronization switch to set. The value **true** means to enable this function; the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
**Example**
```js
......@@ -78,6 +94,7 @@ Changes the device-cloud file synchronization switch for an application. This AP
}
});
```
## cloudSyncManager.notifyDataChange
notifyDataChange(accountId: string, bundleName: string): Promise&lt;void&gt;;
......@@ -99,6 +116,15 @@ Notifies the cloud and device services of the application data change in the clo
| --------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the application data change in the cloud.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
**Example**
```js
......@@ -127,6 +153,15 @@ Notifies the cloud and device services of the application data change in the clo
| bundleName | string | Yes | Bundle name of the application.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the application data change in the cloud.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
**Example**
```js
......
# @ohos.file.environment (Directory Environment Capability)
The **Environment** module provides APIs for obtaining the root directories of the storage and public files.
The **Environment** module provides APIs for obtaining the root directories of the storage and user files.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import
......@@ -28,6 +27,15 @@ Obtains the root directory of the storage. This API uses a promise to return the
| --------------------- | ---------------- |
| Promise&lt;string&gt; | Promise used to return the root directory of the storage.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 202 | The caller is not a system application |
| 13900020 | Invalid argument |
| 13900042 | Unknown error |
**Example**
```js
......@@ -52,6 +60,15 @@ Obtains the root directory of the storage. This API uses an asynchronous callbac
| -------- | --------------------------- | ---- | -------------------------------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Asynchronous callback invoked to return the root directory of the storage.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 202 | The caller is not a system application |
| 13900020 | Invalid argument |
| 13900042 | Unknown error |
**Example**
```js
......@@ -68,7 +85,7 @@ Obtains the root directory of the storage. This API uses an asynchronous callbac
getUserDataDir():Promise&lt;string&gt;
Obtains the root directory of public files. This API uses a promise to return the result.
Obtains the root directory of user files. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.Environment
......@@ -76,7 +93,16 @@ Obtains the root directory of public files. This API uses a promise to return th
| Type | Description |
| --------------------- | ------------------ |
| Promise&lt;string&gt; | Promise returned with the root directory of public files.|
| Promise&lt;string&gt; | Promise used to return the root directory of user files.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 202 | The caller is not a system application |
| 13900020 | Invalid argument |
| 13900042 | Unknown error |
**Example**
......@@ -92,7 +118,7 @@ Obtains the root directory of public files. This API uses a promise to return th
getUserDataDir(callback:AsyncCallback&lt;string&gt;): void
Obtains the root directory of public files. This API uses an asynchronous callback to return the result.
Obtains the root directory of user files. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.Environment
......@@ -100,7 +126,16 @@ Obtains the root directory of public files. This API uses an asynchronous callba
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------------------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Asynchronous callback used to return the root directory of public files.|
| callback | AsyncCallback&lt;string&gt; | Yes | Asynchronous callback used to return the root directory of user files.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 202 | The caller is not a system application |
| 13900020 | Invalid argument |
| 13900042 | Unknown error |
**Example**
......
......@@ -41,9 +41,9 @@ Obtains the URI of a file in synchronous mode.
**Return value**
| Type | Description |
| ---------------------------- | ---------- |
| string | File URI obtained.|
| Type | Description |
| ---------------------------- | ---------- |
| string | File URI obtained.|
**Error codes**
......@@ -52,7 +52,6 @@ For details about the error codes, see [File Management Error Codes](../errorcod
| ---------------------------- | ---------- |
| 401 | The input parameter is invalid |
**Example**
```js
......
......@@ -14,7 +14,7 @@ import fs from '@ohos.file.fs';
## Guidelines
Before using the APIs provided by this module to perform operations on a file or folder, obtain the application sandbox path of the file or folder as follows:
Before using the APIs provided by this module to perform operations on a file or directory, obtain the application sandbox path of the file or directory as follows:
**Stage Model**
......@@ -29,7 +29,7 @@ export default class EntryAbility extends UIAbility {
}
```
**FA Model**
FA Model
```js
import featureAbility from '@ohos.ability.featureAbility';
......@@ -58,13 +58,13 @@ Obtains detailed file information. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -94,7 +94,7 @@ Obtains detailed file information. This API uses an asynchronous callback to ret
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -120,17 +120,17 @@ Obtains detailed file information synchronously.
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| file | string\|number | Yes | Application sandbox path or FD of the file.|
| file | string\|number | Yes | Application sandbox path or file descriptor (FD) of the file.|
**Return value**
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -155,13 +155,13 @@ Checks whether a file exists. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file exists; the value **false** means the opposite.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file exists; the value **false** means the opposite.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -193,7 +193,7 @@ Checks whether a file exists. This API uses an asynchronous callback to return t
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -226,13 +226,13 @@ Synchronously checks whether a file exists.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| boolean | Returns **true** if the file exists; returns **false** otherwise.|
| Type | Description |
| ------------------- | ---------------------------- |
| boolean | Returns **true** if the file exists; returns **false** otherwise.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -259,19 +259,19 @@ Closes a file. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -296,14 +296,14 @@ Closes a file. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked immediately after the file is closed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -329,13 +329,13 @@ Synchronously closes a file.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -355,21 +355,21 @@ Copies a file. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file of the same name.|
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file with the same name in the destination directory. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -393,16 +393,16 @@ Copies a file. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. |
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file with the same name in the destination directory. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked immediately after the file is copied. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -429,15 +429,15 @@ Synchronously copies a file.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file with the same name in the destination directory. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -447,6 +447,93 @@ For details about error codes, see "Basic File I/O Error Codes" in [File Managem
fs.copyFileSync(srcPath, dstPath);
```
## fs.copyDir<sup>10+</sup>
copyDir(src: string, dest: string, mode?: number): Promise\<void>
Copies a directory to the specified directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the directory to copy.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| mode | number | No | Copy mode. The default value is **0**.<br>- **0**: Throw an exception if a file conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles)> format.<br>- **1**: Forcibly overwrite the files with the same name in the destination directory.<br> If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
```js
// Copy srcPath to destPath.
let srcPath = pathDir + "/srcDir/";
let destPath = pathDir + "/destDir/";
fs.copyDir(srcPath, destPath, 0).then(() => {
console.info("copy directory succeed");
}).catch((err) => {
if (err.code == 13900015) {
for (let i = 0; i < err.data.length; i++) {
console.info("copy directory failed with conflicting files: " + err.data[i].srcFile +
" " + err.data[i].destFile);
}
} else {
console.info("copy directory failed with error message: " + err.message + ", error code: " + err.code);
}
});
```
## fs.copyDir<sup>10+</sup>
copyDir(src: string, dest: string, mode?: number, callback: AsyncCallback\<void>): void
Copies a directory to the specified directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the directory to copy.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| mode | number | No | Copy mode. The default value is **0**.<br>- **0**: Throw an exception if a file conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles)> format.<br>- **1**: Forcibly overwrite the files with the same name in the destination directory.<br> If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked immediately after the directory is copied. |
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
```js
// Copy srcPath to destPath.
let srcPath = pathDir + "/srcDir/";
let destPath = pathDir + "/destDir/";
fs.copyDir(srcPath, destPath, 0, (err) => {
if (err && err.code == 13900015) {
for (let i = 0; i < err.data.length; i++) {
console.info("copy directory failed with conflicting files: " + err.data[i].srcFile +
" " + err.data[i].destFile);
}
} else if (err) {
console.info("copy directory failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("copy directory succeed");
}
});
```
## fs.mkdir
mkdir(path: string): Promise&lt;void&gt;
......@@ -463,13 +550,13 @@ Creates a directory. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -499,7 +586,7 @@ Creates a directory. This API uses an asynchronous callback to return the result
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -530,7 +617,7 @@ Synchronously creates a directory.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -556,13 +643,13 @@ Opens a file. This API uses a promise to return the result. File uniform resourc
**Return value**
| Type | Description |
| --------------------- | ----------- |
| Promise&lt;[File](#file)&gt; | Promise used to return the file object.|
| Type | Description |
| --------------------- | ----------- |
| Promise&lt;[File](#file)&gt; | Promise used to return the file object.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -593,7 +680,7 @@ Opens a file. This API uses an asynchronous callback to return the result. File
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -625,13 +712,13 @@ Synchronously opens a file. File URIs are supported.
**Return value**
| Type | Description |
| ------ | ----------- |
| [File](#file) | File object opened.|
| Type | Description |
| ------ | ----------- |
| [File](#file) | File object opened.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -660,13 +747,13 @@ Reads data from a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.|
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -693,16 +780,16 @@ Reads data from a file. This API uses an asynchronous callback to return the res
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is read asynchronously. |
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is read asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -731,21 +818,21 @@ Synchronously reads data from a file.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
**Return value**
| Type | Description |
| ------ | -------- |
| number | Length of the data read.|
| Type | Description |
| ------ | -------- |
| number | Length of the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -773,13 +860,13 @@ Deletes a directory. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -809,7 +896,7 @@ Deletes a directory. This API uses an asynchronous callback to return the result
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -840,7 +927,7 @@ Synchronously deletes a directory.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -865,13 +952,13 @@ Deletes a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -897,11 +984,11 @@ Deletes a file. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- |
| 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 immediately after the file is deleted. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -932,7 +1019,7 @@ Synchronously deletes a file.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -952,21 +1039,21 @@ Writes data into a file. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -991,16 +1078,16 @@ Writes data into a file. This API uses an asynchronous callback to return the re
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1027,21 +1114,21 @@ Synchronously writes data into a file.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
| Type | Description |
| ------ | -------- |
| number | Length of the data written in the file.|
| Type | Description |
| ------ | -------- |
| number | Length of the data written in the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1070,13 +1157,13 @@ Truncates a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1108,7 +1195,7 @@ Truncates a file. This API uses an asynchronous callback to return the result.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1141,7 +1228,7 @@ Synchronously truncates a file.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1168,13 +1255,13 @@ Reads the text content of a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content read.|
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1205,7 +1292,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1237,13 +1324,13 @@ Synchronously reads the text of a file.
**Return value**
| Type | Description |
| ------ | -------------------- |
| string | Promise used to return the content of the file read.|
| Type | Description |
| ------ | -------------------- |
| string | Promise used to return the content of the file read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1269,13 +1356,13 @@ Obtains information about a symbolic link. This API uses a promise to return the
**Return value**
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the symbolic link information obtained. For details, see **stat**.|
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the symbolic link information obtained. For details, see **stat**.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1305,7 +1392,7 @@ Obtains information about a symbolic link. This API uses an asynchronous callbac
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1336,13 +1423,13 @@ Obtains information about a symbolic link synchronously.
**Return value**
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1368,13 +1455,13 @@ Renames a file or folder. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1406,7 +1493,7 @@ Renames a file or folder. This API uses an asynchronous callback to return the r
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1439,7 +1526,7 @@ Renames a file or folder synchronously.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1459,19 +1546,19 @@ Flushes data of a file to disk. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1495,14 +1582,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | FD of the file. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | FD of the file. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1530,13 +1617,13 @@ Flushes data of a file to disk synchronously.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1557,19 +1644,19 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1594,14 +1681,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- |
| fd | number | Yes | FD of the file. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- |
| fd | number | Yes | FD of the file. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1628,13 +1715,13 @@ Synchronizes data in a file synchronously.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1662,13 +1749,13 @@ Creates a symbolic link based on a file path. This API uses a promise to return
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1700,7 +1787,7 @@ Creates a symbolic link based on a file path. This API uses an asynchronous call
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1733,7 +1820,7 @@ Synchronously creates a symbolic link based on a file path.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1750,34 +1837,34 @@ listFile(path: string, options?: {
filter?: Filter;
}): Promise<string[]>
Lists all files in a directory. This API uses a promise to return the result.<br>This API supports recursive listing of all files (including files in subdirectories) and file filtering.
Lists all files in a folder. This API uses a promise to return the result.<br>This API supports recursive listing of all files (including files in subfolders) and file filtering.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Application sandbox path of the folder.|
| options | Object | No | File filtering options. The files are not filtered by default.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Application sandbox path of the folder.|
| options | Object | No | File filtering options. The files are not filtered by default.|
**options parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string[]&gt; | Promise used to return the files names listed.|
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string[]&gt; | Promise used to return the files names listed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1809,27 +1896,27 @@ listFile(path: string, options?: {
filter?: Filter;
}, callback: AsyncCallback<string[]>): void
Lists all files in a directory. This API uses an asynchronous callback to return the result.<br>This API supports recursive listing of all files (including files in subdirectories) and file filtering.
Lists all files in a folder. This API uses an asynchronous callback to return the result.<br>This API supports recursive listing of all files (including files in subfolders) and file filtering.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Application sandbox path of the folder.|
| options | Object | No | File filtering options. The files are not filtered by default.|
| callback | AsyncCallback&lt;string[]&gt; | Yes | Callback invoked to return the file names listed. |
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Application sandbox path of the folder.|
| options | Object | No | File filtering options. The files are not filtered by default.|
| callback | AsyncCallback&lt;string[]&gt; | Yes | Callback invoked to return the file names listed. |
**options parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1864,32 +1951,32 @@ listFileSync(path: string, options?: {
filter?: Filter;
}): string[]
Lists all files in a directory synchronously. This API supports recursive listing of all files (including files in subdirectories) and file filtering.
Lists all files in a folder synchronously. This API supports recursive listing of all files (including files in subfolders) and file filtering.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Application sandbox path of the folder.|
| options | Object | No | File filtering options. The files are not filtered by default.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Application sandbox path of the folder.|
| options | Object | No | File filtering options. The files are not filtered by default.|
**options parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
| Type | Description |
| --------------------- | ---------- |
| string[] | File names listed.|
| Type | Description |
| --------------------- | ---------- |
| string[] | File names listed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -1915,32 +2002,32 @@ For details about error codes, see "Basic File I/O Error Codes" in [File Managem
moveDir(src: string, dest: string, mode?: number): Promise\<void>
Moves a folder. This API uses a promise to return the result.
Moves a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source folder.|
| dest | string | Yes | Application sandbox path of the destination folder.|
| mode | number | No | Mode for moving the folder. The default value is **0**.<br>- **0**: Throw an exception if the destination directory has folders of the same names with the source folder.<br>- **1**: Throw an exception if the destination directory has files of the same names with the source folder. All files without conflicts in the source folder are moved to the destination folder, and all files without conflicts in the destination folder are retained. The **data** in the error thrown provides information about the conflict files.<br>- **2**: Forcibly overwrite the files with the same names in the destination folder. The files with the the same names in the destination folder are overwritten forcibly; the files without conflicts in the destination folder are retained.<br>- **3**: Forcibly overwrite the destination folder. Move the source folder to the destination directory and make the destination folder completely the same as the source folder. All the original files in the destination folder are not retained.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the directory to move.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| mode | number | No | Mode for moving the directory. The default value is **0**.<br>- **0**: Throw an exception if a directory conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory.<br>- **1**: Throw an exception if a file conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles)> format.<br>- **2**: Forcibly overwrite the conflicting files in the destination directory.<br> If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.<br>- **3**: Forcibly overwrite the conflicting directory.<br> Move the source directory to the destination directory and overwrite the conflicting directory completely. That is, if there is a directory with the same name in the destination directory, all the original files in that directory will not be retained.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
```js
// move directory from srcPath to destPath/srcPath
// move directory from srcPath to destPath
let srcPath = pathDir + "/srcDir/";
let destPath = pathDir + "/destDir/";
fs.moveDir(srcPath, destPath, 1).then(() => {
......@@ -1961,27 +2048,27 @@ For details about error codes, see "Basic File I/O Error Codes" in [File Managem
moveDir(src: string, dest: string, mode?: number, callback: AsyncCallback\<void>): void
Moves a folder. This API uses an asynchronous callback to return the result.
Moves a directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source folder.|
| dest | string | Yes | Application sandbox path of the destination folder.|
| mode | number | No | Mode for moving the folder. The default value is **0**.<br>- **0**: Throw an exception if the destination directory has folders of the same names with the source folder.<br>- **1**: Throw an exception if the destination directory has files of the same names with the source folder. All files without conflicts in the source folder are moved to the destination folder, and all files without conflicts in the destination folder are retained. The **data** in the error thrown provides information about the conflict files.<br>- **2**: Forcibly overwrite the files with the same names in the destination folder. The files with the the same names in the destination folder are overwritten forcibly; the files without conflicts in the destination folder are retained.<br>- **3**: Forcibly overwrite the destination folder. Move the source folder to the destination directory and make the destination folder completely the same as the source folder. All the original files in the destination folder are not retained.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the folder is moved. |
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source directory.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| mode | number | No | Mode for moving the directory. The default value is **0**.<br>- **0**: Throw an exception if a directory conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory.<br>- **1**: Throw an exception if a file conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles)> format.<br>- **2**: Forcibly overwrite the conflicting files in the destination directory.<br> If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.<br>- **3**: Forcibly overwrite the conflicting directory.<br> Move the source directory to the destination directory and overwrite the conflicting directory completely. That is, if there is a directory with the same name in the destination directory, all the original files in that directory will not be retained.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is moved. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
```js
// move directory from srcPath to destPath/srcPath
// move directory from srcPath to destPath
let srcPath = pathDir + "/srcDir/";
let destPath = pathDir + "/destDir/";
fs.moveDir(srcPath, destPath, 1, (err) => {
......@@ -2008,21 +2095,21 @@ Moves a file. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file with the same name in the destination directory.<br>The value **0** means to overwrite the file with the same name in the destination directory; the value **1** means to throw an exception.<br>The default value is **0**.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2046,16 +2133,16 @@ Moves a file. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is moved. |
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file with the same name in the destination directory.<br>The value **0** means to overwrite the file with the same name in the destination directory; the value **1** means to throw an exception. <br>The default value is **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is moved. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2081,15 +2168,15 @@ Moves a file synchronously.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file with the same name in the destination directory.<br>The value **0** means to overwrite the file with the same name in the destination directory; the value **1** means to throw an exception. <br>The default value is **0**.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2110,19 +2197,19 @@ Creates a temporary directory. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value**
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the unique directory generated.|
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the unique directory generated.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2144,14 +2231,14 @@ Creates a temporary directory. This API uses an asynchronous callback to return
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. |
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2175,25 +2262,25 @@ Synchronously creates a temporary directory.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value**
| Type | Description |
| ------ | ---------- |
| string | Unique path generated.|
| Type | Description |
| ------ | ---------- |
| string | Unique path generated.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
```js
let res = fs.mkdtempSync(pathDir + "/XXXXXX");
```
```
## fs.createStream
......@@ -2212,13 +2299,13 @@ Creates a stream based on the file path. This API uses a promise to return the r
**Return value**
| Type | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
| Type | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2250,7 +2337,7 @@ Creates a stream based on the file path. This API uses an asynchronous callback
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2282,13 +2369,13 @@ Synchronously creates a stream based on the file path.
**Return value**
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2302,26 +2389,26 @@ For details about error codes, see "Basic File I/O Error Codes" in [File Managem
fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;
Opens a stream based on the FD. This API uses a promise to return the result.
Opens a stream based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value**
| Type | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
| Type | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2340,21 +2427,21 @@ For details about error codes, see "Basic File I/O Error Codes" in [File Managem
fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
Opens a stream based on the FD. This API uses an asynchronous callback to return the result.
Opens a stream based on the file descriptor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is opened. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2375,26 +2462,26 @@ For details about error codes, see "Basic File I/O Error Codes" in [File Managem
fdopenStreamSync(fd: number, mode: string): Stream
Synchronously opens a stream based on the FD.
Synchronously opens a stream based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value**
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2417,21 +2504,21 @@ Creates a **Watcher** object to observe file or directory changes.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Application sandbox path of the file or directory to observe. |
| events | number | Yes | Events to observe. Multiple events can be separated by a bitwise OR operator (&#124;)|.<br>- **0x1: IN_ACCESS**: A file is accessed.<br>- **0x2: IN_MODIFY**: The file content is modified.<br>- **0x4: IN_ATTRIB**: Metadata is changed.<br>- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.<br>- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.<br>- **0x20: IN_OPEN**: A file or directory is opened.<br>- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.<br>- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.<br>- **0x100: IN_CREATE**: A file or directory is created in the observed directory.<br>- **0x200: IN_DELETE**: A file or directory is deleted from the observed directory.<br>- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.<br>- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.<br>- **0xfff: IN_ALL_EVENTS**: All events.|
| listener | WatchEventListener | Yes | Callback invoked when an observed event occurs. The callback will be invoked each time an observed event occurs. |
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Application sandbox path of the file or directory to observe. |
| events | number | Yes | Events to observe. Multiple events can be separated by a bitwise OR operator (&#124;)|.<br>- **0x1: IN_ACCESS**: A file is accessed.<br>- **0x2: IN_MODIFY**: The file content is modified.<br>- **0x4: IN_ATTRIB**: Metadata is changed.<br>- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.<br>- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.<br>- **0x20: IN_OPEN**: A file or directory is opened.<br>- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.<br>- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.<br>- **0x100: IN_CREATE**: A file or directory is created in the observed directory.<br>- **0x200: IN_DELETE**: A file or directory is deleted from the observed directory.<br>- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.<br>- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.<br>- **0xfff: IN_ALL_EVENTS**: All events.|
| listener | WatchEventListener | Yes | Callback invoked when an observed event occurs. The callback will be invoked each time an observed event occurs. |
**Return value**
| Type | Description |
| ------------------ | --------- |
| [Watcher](#watcher10) | **Watcher** object created.|
| Type | Description |
| ------------------ | --------- |
| [Watcher](#watcher10) | **Watcher** object created.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2463,10 +2550,10 @@ Called when an observed event occurs.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| event | WatchEvent | Yes | Event for the callback to invoke. |
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| event | WatchEvent | Yes | Event for the callback to invoke. |
## WatchEvent<sup>10+</sup>
Defines the event to observe.
......@@ -2490,7 +2577,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c
### Attributes
| Name | Type | Readable | Writable | Description |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
| ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| |
| mode | number | Yes | No | File permissions. The meaning of each bit is as follows:<br>- **0o400**: The owner has the read permission on a regular file or a directory entry.<br>- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o040**: The user group has the read permission on a regular file or a directory entry.<br>- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o004**: Other users have the permission to read a regular file or read a directory entry.<br>- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
| uid | number | Yes | No | ID of the file owner.|
......@@ -2510,13 +2597,13 @@ Checks whether this file is a block special file. A block special file supports
**Return value**
| Type | Description |
| ------- | ---------------- |
| boolean | Whether the file is a block special file.|
| Type | Description |
| ------- | ---------------- |
| boolean | Whether the file is a block special file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2535,13 +2622,13 @@ Checks whether this file is a character special file. A character special file s
**Return value**
| Type | Description |
| ------- | ----------------- |
| boolean | Whether the file is a character special file.|
| Type | Description |
| ------- | ----------------- |
| boolean | Whether the file is a character special file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2560,13 +2647,13 @@ Checks whether this file is a directory.
**Return value**
| Type | Description |
| ------- | ------------- |
| boolean | Whether the file is a directory.|
| Type | Description |
| ------- | ------------- |
| boolean | Whether the file is a directory.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2585,13 +2672,13 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**Return value**
| Type | Description |
| ------- | --------------------- |
| boolean | Whether the file is a FIFO.|
| Type | Description |
| ------- | --------------------- |
| boolean | Whether the file is a FIFO.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2610,13 +2697,13 @@ Checks whether this file is a regular file.
**Return value**
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a regular file.|
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a regular file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2635,13 +2722,13 @@ Checks whether this file is a socket.
**Return value**
| Type | Description |
| ------- | -------------- |
| boolean | Whether the file is a socket.|
| Type | Description |
| ------- | -------------- |
| boolean | Whether the file is a socket.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2660,13 +2747,13 @@ Checks whether this file is a symbolic link.
**Return value**
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a symbolic link.|
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a symbolic link.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2689,13 +2776,13 @@ Closes the stream. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.|
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2719,13 +2806,13 @@ Closes the stream. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked immediately after the stream is closed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2736,7 +2823,7 @@ For details about error codes, see "Basic File I/O Error Codes" in [File Managem
if (err) {
console.info("close stream failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("close stream success"):
console.info("close stream success");
}
});
```
......@@ -2751,7 +2838,7 @@ Synchronously closes the stream.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2771,13 +2858,13 @@ Flushes the stream. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.|
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2801,13 +2888,13 @@ Flushes the stream. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2833,7 +2920,7 @@ Synchronously flushes the stream.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2853,20 +2940,20 @@ Writes data into the stream. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2890,15 +2977,15 @@ Writes data into the stream. This API uses an asynchronous callback to return th
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2926,20 +3013,20 @@ Synchronously writes data into the stream.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
| Type | Description |
| ------ | -------- |
| number | Length of the data written in the file.|
| Type | Description |
| ------ | -------- |
| number | Length of the data written in the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2959,20 +3046,20 @@ Reads data from the stream. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
**Return value**
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.|
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -2998,15 +3085,15 @@ Reads data from the stream. This API uses an asynchronous callback to return the
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -3034,20 +3121,20 @@ Synchronously reads data from the stream.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.<br> |
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.<br> |
**Return value**
| Type | Description |
| ------ | -------- |
| number | Length of the data read.|
| Type | Description |
| ------ | -------- |
| number | Length of the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -3079,19 +3166,19 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Return value**
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -3114,14 +3201,14 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is locked. |
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is locked. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -3146,13 +3233,13 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -3172,7 +3259,7 @@ Unlocks this file synchronously.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -3199,7 +3286,7 @@ Starts listening.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -3222,7 +3309,7 @@ Stops listening.
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
......@@ -3266,3 +3353,14 @@ Defines the file filtering configuration, which can be used by **listFile()**.
| fileSizeOver | number | Locate files that are greater than or equal to the specified size. |
| lastModifiedAfter | number | Locate files whose last modification time is the same or later than the specified time. |
| excludeMedia | boolean | Whether to exclude the files already in **Media**. |
## ConflictFiles
**System capability**: SystemCapability.FileManagement.File.FileIO
Defines information about the conflicting files. It is used the **copyDir()** and **moveDir()**.
| Name | Type | Description |
| ----------- | --------------- | ------------------ |
| srcFile | string | Path of the source file. |
| destFile | string | Path of the destination file.|
# @ohos.file.hash (File Hash Processing)
The **fileHash** module implements hash processing on files.
The **FileHash** module implements hash processing on files.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
......@@ -17,7 +16,7 @@ import Hash from '@ohos.file.hash';
Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the file or directory in the application sandbox as follows:
**Stage Model**
Stage Model
```js
import UIAbility from '@ohos.app.ability.UIAbility';
......@@ -30,7 +29,7 @@ export default class EntryAbility extends UIAbility {
}
```
**FA Model**
FA Model
```js
import featureAbility from '@ohos.ability.featureAbility';
......@@ -64,6 +63,15 @@ Calculates a hash value for a file. This API uses a promise to return the result
| --------------------- | -------------------------- |
| Promise&lt;string&gt; | Promise used to return the hash value. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
| ID| Error Message|
| -------- | -------- |
| 13900020 | Invalid argument |
| 13900042 | Unknown error |
**Example**
```js
......@@ -89,9 +97,19 @@ Calculates a hash value for a file. This API uses an asynchronous callback to re
| --------- | --------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Path of the file in the application sandbox. |
| 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 obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
| ID| Error Message|
| -------- | -------- |
| 13900020 | Invalid argument |
| 13900042 | Unknown error |
**Example**
```js
let filePath = pathDir + "/test.txt";
Hash.hash(filePath, "sha256", (err, str) => {
......
......@@ -7,6 +7,7 @@
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import picker from '@ohos.file.picker';
```
......
......@@ -4,8 +4,7 @@ The **securityLabel** module provides APIs for managing data security levels of
> **NOTE**
>
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
......@@ -60,9 +59,24 @@ Sets a security label for a file in asynchronous mode. This API uses a promise t
**Return value**
| Type | Description |
| ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
| ID| Error Message|
| -------- | -------- |
| 13900001 | Operation not permitted |
| 13900007 | Arg list too long |
| 13900015 | File exists |
| 13900020 | Invalid argument |
| 13900025 | No space left on device |
| 13900037 | No data available |
| 13900041 | Quota exceeded |
| 13900042 | Unknown error |
**Example**
......@@ -91,6 +105,21 @@ Sets a security label for a file in asynchronous mode. This API uses an asynchro
| type | DataLevel | Yes | File security level to set, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
| ID| Error Message|
| -------- | -------- |
| 13900001 | Operation not permitted |
| 13900007 | Arg list too long |
| 13900015 | File exists |
| 13900020 | Invalid argument |
| 13900025 | No space left on device |
| 13900037 | No data available |
| 13900041 | Quota exceeded |
| 13900042 | Unknown error |
**Example**
```js
......@@ -119,6 +148,21 @@ Sets a security label for a file in synchronous mode.
| path | string | Yes | Path of the target file. |
| type | DataLevel | Yes | File security level to set, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
| ID| Error Message|
| -------- | -------- |
| 13900001 | Operation not permitted |
| 13900007 | Arg list too long |
| 13900015 | File exists |
| 13900020 | Invalid argument |
| 13900025 | No space left on device |
| 13900037 | No data available |
| 13900041 | Quota exceeded |
| 13900042 | Unknown error |
**Example**
```js
......@@ -136,15 +180,30 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------- |
| path | string | Yes | Path of the target file.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------- |
| path | string | Yes | Path of the target file.|
**Return value**
| Type | Description |
| --------------------- | ------------ |
| Promise&lt;string&gt; | Security label obtained.|
| Type | Description |
| --------------------- | ------------ |
| Promise&lt;string&gt; | Security label obtained.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
| ID| Error Message|
| -------- | -------- |
| 13900001 | Operation not permitted |
| 13900007 | Arg list too long |
| 13900015 | File exists |
| 13900020 | Invalid argument |
| 13900025 | No space left on device |
| 13900037 | No data available |
| 13900041 | Quota exceeded |
| 13900042 | Unknown error |
**Example**
......@@ -167,10 +226,25 @@ Obtains the security label of a file in asynchronous mode. This API uses a callb
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the security label obtained.|
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------------- |
| path | string | Yes | Path of the target file. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the security label obtained.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
| ID| Error Message|
| -------- | -------- |
| 13900001 | Operation not permitted |
| 13900007 | Arg list too long |
| 13900015 | File exists |
| 13900020 | Invalid argument |
| 13900025 | No space left on device |
| 13900037 | No data available |
| 13900041 | Quota exceeded |
| 13900042 | Unknown error |
**Example**
......@@ -184,6 +258,7 @@ Obtains the security label of a file in asynchronous mode. This API uses a callb
}
});
```
## securityLabel.getSecurityLabelSync
getSecurityLabelSync(path:string):string
......@@ -204,6 +279,21 @@ Obtains the security label of a file in synchronous mode.
| ------ | ------------ |
| string | Security label obtained.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
| ID| Error Message|
| -------- | -------- |
| 13900001 | Operation not permitted |
| 13900007 | Arg list too long |
| 13900015 | File exists |
| 13900020 | Invalid argument |
| 13900025 | No space left on device |
| 13900037 | No data available |
| 13900041 | Quota exceeded |
| 13900042 | Unknown error |
**Example**
```js
......
......@@ -4,14 +4,14 @@ The **statfs** module provides APIs for obtaining file system information, inclu
> **NOTE**
>
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import statvfs from '@ohos.file.statvfs';
```
## statvfs.getFreeSize
getFreeSize(path:string):Promise&lt;number&gt;
......@@ -32,6 +32,10 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
| --------------------- | -------------- |
| Promise&lt;number&gt; | Promise used to return the number of free bytes obtained.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
```js
......@@ -58,6 +62,10 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
| path | string | Yes | File path of the file system.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of free bytes obtained.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
```js
......@@ -91,6 +99,10 @@ Obtains the total number of bytes of the specified file system in asynchronous m
| --------------------- | ------------ |
| Promise&lt;number&gt; | Promise used to return the total number of bytes obtained.|
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
```js
......@@ -117,6 +129,10 @@ Obtains the total number of bytes of the specified file system in asynchronous m
| path | string | Yes | File path of the file system.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the total number of bytes obtained. |
**Error codes**
For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
**Example**
```js
......
......@@ -4,8 +4,8 @@ The **storageStatistics** module provides APIs for obtaining storage space infor
> **NOTE**
>
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
......@@ -24,7 +24,6 @@ Obtains the total size (in bytes) of the specified volume in an external storage
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description|
......@@ -37,6 +36,19 @@ Obtains the total size (in bytes) of the specified volume in an external storage
| --------------------- | ---------------- |
| Promise&lt;number&gt; | Promise used to return the total volume size obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -60,7 +72,6 @@ Obtains the total size (in bytes) of the specified volume in an external storage
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
......@@ -68,6 +79,19 @@ Obtains the total size (in bytes) of the specified volume in an external storage
| volumeUuid | string | Yes | UUID of the volume. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the total volume size obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -90,7 +114,6 @@ Obtains the available space (in bytes) of the specified volume in an external st
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description|
......@@ -103,6 +126,19 @@ Obtains the available space (in bytes) of the specified volume in an external st
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the available volume space obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -127,7 +163,6 @@ Obtains the available space (in bytes) of the specified volume in an external st
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
......@@ -135,6 +170,19 @@ Obtains the available space (in bytes) of the specified volume in an external st
| volumeUuid | string | Yes | UUID of the volume. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the available volume space obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -157,7 +205,6 @@ Obtains the space (in bytes) of an application. This API uses a promise to retur
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
......@@ -170,6 +217,19 @@ Obtains the space (in bytes) of an application. This API uses a promise to retur
| ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the application space obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -193,7 +253,6 @@ Obtains the space (in bytes) of an application. This API uses an asynchronous ca
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
......@@ -201,6 +260,19 @@ Obtains the space (in bytes) of an application. This API uses an asynchronous ca
| packageName | string | Yes | Bundle name of the application.|
| callback | AsyncCallback&lt;[Bundlestats](#bundlestats9)&gt; | Yes | Callback invoked to return the application space obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -225,6 +297,16 @@ Obtains the space (in bytes) of this third-party application. This API uses a pr
| ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the application space obtained. |
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -246,6 +328,16 @@ Obtains the space (in bytes) of this third-party application. This API uses an a
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt; | Yes | Callback invoked to return the application space obtained. |
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -265,7 +357,6 @@ Obtains the space (in bytes) of this third-party application. This API uses an a
| cacheSize | number | Yes| No| Cache size of the application, in bytes. |
| dataSize | number | Yes| No| Total data size of the application, in bytes.|
## storageStatistics.getTotalSize<sup>9+</sup>
getTotalSize(): Promise&lt;number&gt;
......@@ -284,6 +375,18 @@ Obtains the total size (in bytes) of the built-in storage. This API uses a promi
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the built-in storage size obtained. |
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -309,6 +412,18 @@ Obtains the total size (in bytes) of the built-in storage. This API uses an asyn
| -------- | ------------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the built-in storage size obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -318,7 +433,6 @@ Obtains the total size (in bytes) of the built-in storage. This API uses an asyn
});
```
## storageStatistics.getFreeSize<sup>9+</sup>
getFreeSize(): Promise&lt;number&gt;
......@@ -337,6 +451,18 @@ Obtains the available space (in bytes) of the built-in storage. This API uses a
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the available space of the built-in storage obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -344,7 +470,6 @@ Obtains the available space (in bytes) of the built-in storage. This API uses a
console.info("getFreeSize successfully:"+ JSON.stringify(number));
```
## storageStatistics.getFreeSize<sup>9+</sup>
getFreeSize(callback: AsyncCallback&lt;number&gt;): void
......@@ -363,6 +488,18 @@ Obtains the available space (in bytes) of the built-in storage. This API uses an
| -------- | ------------------------------------ | ---- | ------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the available space of the built-in storage obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -384,13 +521,24 @@ Obtains the system data space, in bytes. This API uses a promise to return the r
**System API**: This is a system API.
**Return value**
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;number&gt; | Promise used to return the system data space obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -419,6 +567,18 @@ Obtains the system data space, in bytes. This API uses an asynchronous callback
| ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the system data space obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -446,6 +606,18 @@ Obtains the storage statistics (in bytes) of this user. This API uses a promise
| --------------------- | ---------------- |
| Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the information obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -474,6 +646,18 @@ Obtains the storage statistics (in bytes) of this user. This API uses an asynchr
| ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes | Callback invoked to return the information obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -482,6 +666,9 @@ Obtains the storage statistics (in bytes) of this user. This API uses an asynchr
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
});
```
## storageStatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
Obtains the storage statistics (in bytes) of the specified user. This API uses a promise to return the result.
......@@ -504,6 +691,19 @@ Obtains the storage statistics (in bytes) of the specified user. This API uses a
| --------------------- | ---------------- |
| Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the information obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600009 | User if out of range. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -534,6 +734,19 @@ Obtains the storage statistics (in bytes) of the specified user. This API uses a
| userId | number | Yes | User ID.|
| callback | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes | Callback invoked to return the information obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600009 | User if out of range. |
| 13900032 | Unknown error. |
**Example**
```js
......@@ -544,7 +757,6 @@ Obtains the storage statistics (in bytes) of the specified user. This API uses a
});
```
## StorageStats<sup>9+</sup>
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
......
......@@ -6,7 +6,6 @@ The **volumeManager** module provides APIs for volume and disk management, inclu
>
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are system APIs.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import
......@@ -26,9 +25,21 @@ Obtains information about all volumes of this external storage device. This API
**Return value**
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)[]&gt; | Promise used to return information about all available volumes.|
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)[]&gt; | Promise used to return information about all available volumes.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
......@@ -52,9 +63,21 @@ Obtains information about all volumes of this external storage device. This API
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback&lt;[Volume](#volume)[]&gt; | Yes | Callback invoked to return information about all available volumes.|
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback&lt;[Volume](#volume)[]&gt; | Yes | Callback invoked to return information about all available volumes.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |
**Example**
......@@ -65,7 +88,6 @@ Obtains information about all volumes of this external storage device. This API
});
```
## volumemanager.mount
mount(volumeId: string): Promise&lt;void&gt;
......@@ -78,15 +100,31 @@ Asynchronously mounts a volume. This API uses a promise to return the result. Cu
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
**Return value**
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600002 | Not supported filesystem. |
| 13600003 | Failed to mount. |
| 13600005 | Incorrect volume state. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -111,10 +149,26 @@ Asynchronously mounts a volume. This API uses an asynchronous callback to return
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600002 | Not supported filesystem. |
| 13600003 | Failed to mount. |
| 13600005 | Incorrect volume state. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -137,15 +191,31 @@ Asynchronously unmounts a volume. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
**Return value**
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600002 | Not supported filesystem. |
| 13600004 | Failed to unmount. |
| 13600005 | Incorrect volume state. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -170,10 +240,26 @@ Asynchronously unmounts a volume. This API uses an asynchronous callback to retu
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600002 | Not supported filesystem. |
| 13600004 | Failed to unmount. |
| 13600005 | Incorrect volume state. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -196,15 +282,28 @@ Obtains information about a volume based on the universally unique identifier (U
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.|
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.|
**Return value**
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.|
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -229,10 +328,23 @@ Obtains information about a volume based on the UUID. This API uses an asynchron
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | -------------------- |
| uuid | string | Yes | UUID of the volume. |
| callback | AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained.|
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | -------------------- |
| uuid | string | Yes | UUID of the volume. |
| callback | AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -255,15 +367,28 @@ Obtains information about a volume based on the volume ID. This API uses a promi
**Parameters**
| Name | Type | Mandatory | Description|
| -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
| Name | Type | Mandatory | Description|
| -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
**Return value**
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.|
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -288,10 +413,23 @@ Obtains information about a volume based on the volume ID. This API uses an asyn
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- |
| volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained. |
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- |
| volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained. |
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -314,16 +452,31 @@ Sets volume description. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory| Description|
| --------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.|
| description | string | Yes | Volume description to set.|
| Name | Type | Mandatory| Description|
| --------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.|
| description | string | Yes | Volume description to set.|
**Return value**
| Type | Description |
| ---------------------- | -------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
| Type | Description |
| ---------------------- | -------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. |
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600002 | Not supported filesystem. |
| 13600005 | Incorrect volume state. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -349,11 +502,26 @@ Sets volume description. This API uses an asynchronous callback to return the re
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ---------------- |
| uuid | string | Yes | UUID of the volume. |
| description | string | Yes | Volume description to set. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ---------------- |
| uuid | string | Yes | UUID of the volume. |
| description | string | Yes | Volume description to set. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600002 | Not supported filesystem. |
| 13600005 | Incorrect volume state. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -377,16 +545,31 @@ Formats a volume. This API uses a promise to return the result. Currently, only
**Parameters**
| Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
| fsType | string | Yes | File system type, which can be VFAT or exFAT.|
| Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.|
| fsType | string | Yes | File system type, which can be VFAT or exFAT.|
**Return value**
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600002 | Not supported filesystem. |
| 13600005 | Incorrect volume state. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -412,11 +595,26 @@ Formats a volume. This API uses an asynchronous callback to return the result. C
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- |
| volumeId | string | Yes | Volume ID. |
| fsType | string | Yes | File system type, which can be VFAT or exFAT.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- |
| volumeId | string | Yes | Volume ID. |
| fsType | string | Yes | File system type, which can be VFAT or exFAT.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600002 | Not supported filesystem. |
| 13600005 | Incorrect volume state. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -440,16 +638,29 @@ Partitions a disk. This API uses a promise to return the result. The system supp
**Parameters**
| Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- |
| diskId | string | Yes | ID of the disk to partition.|
| type | number | Yes | Partition type. |
| Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- |
| diskId | string | Yes | ID of the disk to partition.|
| type | number | Yes | Partition type. |
**Return value**
| Type | Description |
| --------------------- | ----------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
| Type | Description |
| --------------------- | ----------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......@@ -475,11 +686,24 @@ Asynchronously partitions a disk. This API uses a callback to return the result.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- |
| diskId | string | Yes | ID of the disk to partition. |
| type | number | Yes | Partition type. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- |
| diskId | string | Yes | ID of the disk to partition. |
| type | number | Yes | Partition type. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |
**Example**
......
# @ohos.fileShare (File Sharing)
# @ohos.fileshare (File Sharing)
The **fileShare** module provides APIs for granting the access permissions on a user file to another application by the Uniform Resource Identifier (URI). Then, the authorized application can access the file by using the APIs provided by [@ohos.file.fs](js-apis-file-fs.md).
The **fileshare** module provides APIs for granting the access permissions on a user file to another application by the Uniform Resource Identifier (URI). Then, the authorized application can access the file by using the APIs provided by [@ohos.file.fs](js-apis-file-fs.md).
> **NOTE**
>
......@@ -9,7 +9,7 @@ The **fileShare** module provides APIs for granting the access permissions on a
## Modules to Import
```js
import fileShare from '@ohos.fileShare';
import fileShare from '@ohos.fileshare';
```
## fileShare.grantUriPermission
......@@ -31,7 +31,7 @@ Grants permissions on a user file by the URI to an application. This API uses an
| uri | string | Yes | URI of a user file.|
| bundleName | string | Yes | Bundle name of the application to be grated with the permissions.|
| mode | number | Yes | Permissions to grant. For details, see [wantConstant.Flags](js-apis-app-ability-wantConstant.md#wantconstantflags).<br>**wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION**: permission to read the file. <br>**wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION**: permission to write the file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Error codes**
......@@ -44,7 +44,6 @@ For details about the error codes, see [File Management Error Codes](../errorcod
| 401 | The input parameter is invalid |
| 143000001 | IPC error |
**Example**
```js
......@@ -66,7 +65,6 @@ try {
}
```
## fileShare.grantUriPermission
grantUriPermission(uri: string, bundleName: string, mode: number): Promise&lt;void&gt;
......@@ -89,10 +87,9 @@ Grants permissions on a user file by the URI to an application. This API uses a
**Return value**
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
......@@ -105,7 +102,6 @@ For details about the error codes, see [File Management Error Codes](../errorcod
| 401 | The input parameter is invalid |
| 143000001 | IPC error |
**Example**
```js
......
......@@ -4,8 +4,8 @@ The **userFileManager** module provides user data management capabilities, inclu
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs provided by this module are system APIs.
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are system APIs.
## Modules to Import
......@@ -49,11 +49,8 @@ let mgr = userFileManager.getUserFileMgr(context);
getPhotoAssets(options: FetchOptions, callback: AsyncCallback&lt;FetchResult&lt;FileAsset&gt;&gt;): void;
Obtains image and video assets. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
......@@ -92,7 +89,6 @@ async function example() {
}
```
### getPhotoAssets
getPhotoAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&gt;;
......@@ -141,6 +137,7 @@ async function example() {
}
}
```
### createPhotoAsset
createPhotoAsset(displayName: string, albumUri: string, callback: AsyncCallback&lt;FileAsset&gt;): void;
......@@ -261,7 +258,6 @@ async function example() {
getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback&lt;FetchResult&lt;Album&gt;&gt;): void;
Obtains image and video albums. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
......@@ -352,7 +348,6 @@ async function example() {
getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback&lt;FetchResult&lt;PrivateAlbum&gt;&gt;): void;
Obtains the system album. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
......@@ -424,7 +419,6 @@ async function example() {
getAudioAssets(options: FetchOptions, callback: AsyncCallback&lt;FetchResult&lt;FileAsset&gt;&gt;): void;
Obtains audio assets. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
......@@ -469,7 +463,6 @@ async function example() {
getAudioAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&gt;;
Obtains audio assets. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
......@@ -515,6 +508,7 @@ async function example() {
}
}
```
### delete
delete(uri: string, callback: AsyncCallback&lt;void&gt;): void;
......@@ -564,6 +558,7 @@ async function example() {
});
}
```
### delete
delete(uri: string): Promise&lt;void&gt;;
......@@ -1093,7 +1088,6 @@ Opens this file asset. This API uses an asynchronous callback to return the resu
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.WRITE_IMAGEVIDEO, or ohos.permission.WRITE_AUDIO
**System capability**: SystemCapability.FileManagement.UserFileManager.Core
**Parameters**
......@@ -1923,6 +1917,7 @@ async function example() {
});
}
```
### getPhotoAssets
getPhotoAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&gt;;
......@@ -2106,6 +2101,7 @@ async function example() {
}
```
### getPhotoAssets
getPhotoAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&gt;;
......@@ -2147,6 +2143,7 @@ async function example() {
console.info('fetchResult.count = ', count);
}
```
### delete
delete(uri: string, callback: AsyncCallback&lt;void&gt;): void;
......@@ -2190,6 +2187,7 @@ async function example() {
});
}
```
### delete
delete(uri: string): Promise&lt;void&gt;;
......@@ -2280,6 +2278,7 @@ async function example() {
});
}
```
### recover
recover(uri: string): Promise&lt;void&gt;;
......@@ -2335,9 +2334,9 @@ Enumerates the member types.
| Name | Type| Readable | Writable | Description |
| ----- | ---- | ---- | ---- | ---- |
| number | number | Yes| Yes| The member is a number.|
| string | string | Yes| Yes| The member is a string.|
| boolean | boolean | Yes| Yes| The member is a Boolean value.|
| number | number | Yes| Yes| The member is a number.|
| string | string | Yes| Yes| The member is a string.|
| boolean | boolean | Yes| Yes| The member is a Boolean value.|
## ChangeEvent
......@@ -2366,7 +2365,6 @@ Defines information about a registered device.
| networkId | string | Yes | No | Network ID of the registered device.|
| isOnline | boolean | Yes | No | Whether the registered device is online. |
## FileType
Enumerates media file types.
......@@ -2390,8 +2388,6 @@ Enumerates the system album types.
| TYPE_FAVORITE | 0 | Favorites.|
| TYPE_TRASH | 1 | Recycle bin.|
## AudioKey
Defines the key information about an audio file.
......@@ -2445,7 +2441,6 @@ Defines the key album information.
| DATE_ADDED | date_added | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. |
| DATE_MODIFIED | date_modified | Date when the file content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.|
## FetchOptions
Defines the options for fetching media files.
......
......@@ -4,9 +4,14 @@
>
> This topic describes only module-specific error codes. For details about universal error codes, see [Universal Error Codes](errorcode-universal.md).
The error codes of the file management subsystem consist of the following:<br>- Basic file I/O error codes<br>- User data management error codes<br>- User file access error codes<br>- Spatial statistics error codes
The error codes of the file management subsystem include the following:
## Basic File I/O Error Codes
- [Basic File IO Error Codes](#basic-file-io-error-codes)
- [User Data Management Error Codes](#user-data-management-error-code)
- [User File Access Error Codes](#user-file-access-error-codes)
- [Space Statistics Error Codes](#space-statistics-error-codes)
## Basic File IO Error Codes
### 13900001 Operation Not Permitted
......@@ -49,6 +54,7 @@ The process does not exist.
**Solution**
1. Check whether the process is killed unexpectedly.
2. Check whether the service related to the process has started.
### 13900004 System Call Interrupted
......@@ -64,6 +70,7 @@ The system call is interrupted by another thread.
**Solution**
1. Check the multi-thread code logic.
2. Invoke the system call again.
### 13900005 I/O Error
......@@ -161,7 +168,9 @@ Out of memory
A memory overflow occurs.
**Solution**
1. Check the memory overhead.
2. Control the memory overhead.
### 13900012 Permission Denied
......@@ -172,13 +181,14 @@ Permission denied
**Possible Causes**
1. You do not have the permission to operate the file.
2. The file sandbox path is incorrect.
**Solution**
1. Check that you have the permission to operate the file.
1. Check that the required permission is available.
2. Check that the file sandbox path is correct.
### 13900013 Incorrect Address
......@@ -375,7 +385,7 @@ Seek is used in pipe or FIFO.
**Solution**
Check the use of seek.
Check the use of **seek()**.
### 13900027 Read-Only File System
......@@ -460,6 +470,7 @@ The specified directory is not empty.
**Solution**
1. Check the directory.
2. Ensure that the directory is empty.
### 13900033 Too Many Symbol Links
......@@ -516,7 +527,7 @@ The device pointed to by the file descriptor is not a character stream device.
**Solution**
Check whether the file descriptor points to a stream device.
Check whether the file descriptor points to a stream.
### 13900037 No Data Available
......@@ -599,7 +610,9 @@ Unknown error
The error is unidentified.
**Solution**
1. Call the API again.
2. Restart the service.
## User Data Management Error Codes
......@@ -636,7 +649,7 @@ Use the obtained URI.
**Error Message**
Invalid file extension
Invalid file name extension
**Possible Causes**
......@@ -660,7 +673,7 @@ The file is moved to the Recycle Bin.
Check whether the file is in the Recycle Bin.
## Spatial Statistics Error Codes
## Space Statistics Error Codes
### 13600001 IPC Failed
......@@ -680,7 +693,7 @@ Check whether the service is started.
**Error Message**
Not supported file system
Not supported filesystem
**Possible Causes**
......@@ -767,11 +780,15 @@ Check whether the specified directory or node exists.
No such object
**Possible Causes**
1. The specified volume ID is incorrect.
2. The specified bundle name is incorrect.
**Solution**
1. Check whether the specified volume exists.
2. Check whether the specified bundle name exists.
### 13600009 Invalid User ID
......@@ -799,6 +816,7 @@ IPC error
**Possible Causes**
1. The server service does not exist.
2. The extension mechanism is abnormal.
**Solution**
......@@ -854,7 +872,9 @@ Check the data returned by the server.
Fail to register notification
**Possible Causes**
1. The server service does not exist.
2. The extension mechanism is abnormal.
**Solution**
......@@ -868,7 +888,9 @@ Check that the server service exists.
Fail to remove notification
**Possible Causes**
1. The server service does not exist.
2. The extension mechanism is abnormal.
**Solution**
......@@ -896,47 +918,11 @@ Check whether the specified Notify agent is registered.
Fail to notify agent
**Possible Causes**
1. The service does not exist.
2. The extension mechanism is abnormal.
**Solution**
Check whether the client is normal.
## Error Code Adaptation
The APIs provided by the file management subsystem support exception handling.
Sample code for exception handling in a synchronous API:
```js
import fs from '@ohos.file.fs'
try {
let file = fs.openSync(path, fs.OpenMode.READ_ONLY);
} catch (err) {
console.error("openSync errCode:" + err.code + ", errMessage:" + err.message);
}
```
Sample code for exception handling in an asynchronous API (promise):
```js
import fs from '@ohos.file.fs'
try {
let file = await fs.open(path, fs.OpenMode.READ_ONLY);
} catch (err) {
console.error("open promise errCode:" + err.code + ", errMessage:" + err.message);
}
```
Sample code for exception handling in an asynchronous API (callback):
```js
import fs from '@ohos.file.fs'
try {
fs.open(path, fs.OpenMode.READ_ONLY, function(e, file){ // Asynchronous thread (such as the system call) errors are obtained via a callback.
if (e) {
console.error("open in async errCode:" + e.code + ", errMessage:" + e.message);
}
});
} catch (err) {// Main thread errors (such as invalid parameters) are obtained by try catch.
console.error("open callback errCode:" + err.code + ", errMessage:" + err.message);
}
```
......@@ -2,11 +2,11 @@
## cl.filemanagement.1 environment Module Change
The file management subsystem **d.ts** file has been archived and moved to the **file** directory. The **environment** module supports error code handling.
The file management subsystem **d.ts** file has been archived and moved to the **file** directory. The **environment** module supports error code processing.
**Change Impact**
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **environment** module supports error code handling. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md).
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **environment** module supports error code processing. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md) for more details.
**Key API/Component Changes**
......@@ -24,11 +24,11 @@ import environment from '@ohos.file.environment';
## cl.filemanagement.2 securityLabel Change
Moved the file management subsystem **d.ts** file to the **file** directory. The **securityLabel** module supports error code handling.
Moved the file management subsystem **d.ts** file to the **file** directory. The **securityLabel** module supports error code processing.
**Change Impact**
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **securityLabel** module supports error code handling. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md).
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **securityLabel** module supports error code processing. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md) for more details.
**Key API/Component Changes**
......@@ -58,11 +58,11 @@ The type of the **ino** attribute of **Stat** is changed from number to BigInt.
## cl.filemanagement.4 fileAccess Change
Moved the file management subsystem **d.ts** file to the **file** directory. The **fileAccess** module supports error code handling.
Moved the file management subsystem **d.ts** file to the **file** directory. The **fileAccess** module supports error code processing.
**Change Impact**
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **fileAccess** module supports error code handling. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md).
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **fileAccess** module supports error code processing. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md) for more details.
**Key API/Component Changes**
......@@ -80,11 +80,11 @@ import fileAccess from '@ohos.file.fileAccess';
## cl.filemanagement.5 fileExtensionInfo Change
Moved the file management subsystem **d.ts** file to the **file** directory. The **fileExtensionInfo** module supports error code handling.
Moved the file management subsystem **d.ts** file to the **file** directory. The **fileExtensionInfo** module supports error code processing.
**Change Impact**
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **fileExtensionInfo** module supports error code handling. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md).
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **fileExtensionInfo** module supports error code processing. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md) for more details.
**Key API/Component Changes**
......@@ -102,11 +102,11 @@ import fileExtensionInfo from '@ohos.file.fileExtensionInfo';
## cl.filemanagement.6 storageStatistics Change
Moved the file management subsystem **d.ts** file to the **file** directory. The **fileExtensionInfo** module supports error code handling.
Moved the file management subsystem **d.ts** file to the **file** directory. The **fileExtensionInfo** module supports error code processing.
**Change Impact**
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **storageStatistics** module supports error code handling. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md).
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **storageStatistics** module supports error code processing. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md) for more details.
**Key API/Component Changes**
......@@ -124,11 +124,11 @@ import storageStatistics from '@ohos.file.storageStatistics';
## cl.filemanagement.7 volumeManager Change
Moved the file management subsystem **d.ts** file to the **file** directory. The **fileExtensionInfo** module supports error code handling.
Moved the file management subsystem **d.ts** file to the **file** directory. The **fileExtensionInfo** module supports error code processing.
**Change Impact**
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **volumeManager** module supports error code handling. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md).
If your application is developed based on earlier versions, note that the **d.ts** file location and the name of the module to be imported are changed. The **volumeManager** module supports error code processing. See [Adaptation Guide](../OpenHarmony_3.2.8.1/changelogs-filemanagement.md) for more details.
**Key API/Component Changes**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册