提交 2feb5a29 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 fc4b7c80
# @ohos.file.fileAccess (User File Access and Management)
The **fileAccess** module is a framework for accessing and operating user files based on the Extension ability mechanism. This module interacts with diverse file management services, such as the media library and external storage management service, and provides a set of file access and management APIs for system applications. The media library service allows access to user files on local devices and distributed devices. The external storage management service allows access to the user files stored on devices such as shared disks, USB flash drives, and SD cards.
The **fileAccess** module provides a framework for accessing and operating user files based on the ExtensionAbility mechanism. This module interacts with file management services, such as the media library and external storage management service, and provides a set of unified interfaces for system applications to access and manage files. The media library service allows access to user files on local and distributed devices. The external storage management service allows access to the user files stored on devices, such as shared disks, USB flash drives, and SD cards.
>**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 and cannot be called by third-party applications. Currently, the APIs can be called only by **FilePicker** and **Files**.
>- 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.
> - The APIs provided by this module are system APIs and cannot be called by third-party applications. Currently, the APIs can be called only by **FilePicker** and **FileManager**.
## Modules to Import
......@@ -16,9 +15,11 @@ import fileAccess from '@ohos.file.fileAccess';
## fileAccess.getFileAccessAbilityInfo
getFileAccessAbilityInfo( ) : Promise&lt;Array&lt;Want&gt;&gt;
getFileAccessAbilityInfo() : Promise&lt;Array&lt;Want&gt;&gt;
Obtains information about all wants with **extension** set to **fileAccess** in the system. A want is a basic communication component used to start services. This API uses a promise to return the result.
Obtains information about all Wants with **extension** set to **fileAccess** in the system. A Want contains information for starting an ability. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -26,9 +27,13 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;Array&lt;Want&gt;&gt; | Promise used to return the **want** information obtained.|
| Type| Description|
| --- | -- |
| Promise&lt;Array&lt;[Want](js-apis-app-ability-want.md)&gt;&gt; | Promise used to return the Want information obtained.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -46,9 +51,11 @@ Obtains information about all wants with **extension** set to **fileAccess** in
## fileAccess.getFileAccessAbilityInfo
getFileAccessAbilityInfo(callback: AsyncCallback&lt;Array&lt;Want&gt;&gt;): void;
getFileAccessAbilityInfo(callback: AsyncCallback&lt;Array&lt;Want&gt;&gt;): void
Obtains information about all Wants with **extension** set to **fileAccess** in the system. A Want contains information for starting an ability. This API uses an asynchronous callback to return the result.
Obtains information about all wants with **extension** set to **fileAccess** in the system. A want is a basic communication component used to start services. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -56,9 +63,13 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;Array&lt;Want&gt;&gt; | Yes| Promise used to return the **want** information obtained.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;Array&lt;[Want](js-apis-app-ability-want.md)&gt;&gt; | Yes| Promise used to return the Want information obtained.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -84,22 +95,28 @@ createFileAccessHelper(context: Context, wants: Array&lt;Want&gt;) : FileAccessH
Synchronously creates a **Helper** object to connect to the specified wants. The **Helper** object provides file access and management capabilities.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| wants | Array&lt;Want&gt; | Yes| Wants to connect.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | [Context](js-apis-inner-application-context.md) | Yes| Context of the ability.|
| wants | Array&lt;[Want](js-apis-app-ability-want.md)&gt; | Yes| Wants to connect.|
**Return value**
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| Type| Description|
| --- | -- |
| [FileAccessHelper](#fileaccesshelper) | **Helper** object created.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -131,21 +148,27 @@ createFileAccessHelper(context: Context) : FileAccessHelper
Synchronously creates a **Helper** object to connect to all file management services in the system.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | [Context](js-apis-inner-application-context.md) | Yes| Context of the ability.|
**Return value**
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| Type| Description|
| --- | -- |
| [FileAccessHelper](#fileaccesshelper) | **Helper** object created.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -164,56 +187,90 @@ Synchronously creates a **Helper** object to connect to all file management serv
}
```
## FileAccessHelper.getRoots
## FileInfo
Provides the file or directory attribute information and APIs.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
### Attributes
| Name| Type | Readable| Writable| Description |
| ------ | ------ | -------- | ------ | -------- |
| uri | string | Yes| No| URI of the file or directory.|
| fileName | string | Yes| No| Name of the file or directory.|
| mode | number | Yes| No| Permissions on the file or directory.|
| size | number | Yes| No| Size of the file or directory.|
| mtime | number | Yes| No| Time when the file or directory was last modified.|
| mimeType | string | Yes| No| Multipurpose Internet Mail Extensions (MIME) type of the file or directory.|
### listFile
getRoots( ) : Promise&lt;RootIterator&gt;
listFile(filter?: Filter) : FileIterator
Synchronously obtains a **FileIterator** object that lists the next-level files (directories) matching the conditions of the filter from a directory and returns [FileInfo](#fileinfo) using [next()](#next). Currently, only built-in storage devices support the file filter.
Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses a promise to return a **RootIterator** object, which returns [RootInfo](#rootinfo) by using [next()](#rootiteratornext).
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | [Filter](js-apis-file-fs.md#filter) | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;RootIterator&gt; | Promise used to return the **RootIterator** object obtained.|
| Type| Description|
| --- | -- |
| [FileIterator](#fileiterator) | **FileIterator** object obtained.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
async getRoots() {
let rootIterator = null;
let rootinfos = [];
// fileInfoDir indicates information about a directory.
// let filter = { suffix : [".txt", ".jpg", ".xlsx"] };
let fileInfoDir = fileInfos[0];
let subfileInfos = [];
let isDone = false;
try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
rootIterator = await fileAccessHelper.getRoots();
if (!rootIterator) {
console.error("getRoots interface returns an undefined object");
let fileIterator = fileInfoDir.listFile();
// listFile() with the filter implementation.
// let fileIterator = rootInfo.listFile(filter);
if (!fileIterator) {
console.error("listFile interface returns an undefined object");
return;
}
while (!isDone) {
let result = rootIterator.next();
let result = fileIterator.next();
console.log("next result = " + JSON.stringify(result));
isDone = result.done;
if (!isDone)
rootinfos.push(result.value);
subfileInfos.push(result.value);
}
} catch (error) {
console.error("getRoots failed, errCode:" + error.code + ", errMessage:" + error.message);
}
console.error("listFile failed, errCode:" + error.code + ", errMessage:" + error.message);
}
```
## FileAccessHelper.getRoots
### scanFile
getRoots(callback:AsyncCallback&lt;RootIterator&gt;) : void;
scanFile(filter?: Filter) : FileIterator
Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses an asynchronous callback to return the result.
Synchronously obtains a **FileIterator** object that recursively retrieves the files matching the conditions of the filter from a directory and returns [FileInfo](#fileinfo) using [next()](#next). Currently, this API supports only built-in storage devices.
The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) through [next()](#rootiteratornext).
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -221,59 +278,126 @@ The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo)
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;RootIterator&gt; | Yes| Promise used to return the **RootIterator** object obtained.|
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | [Filter](js-apis-file-fs.md#filter) | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| [FileIterator](#fileiterator) | **FileIterator** object obtained.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
async getRoots() {
let rootinfos = [];
// fileInfoDir indicates information about a directory.
// let filter = {suffix : [".txt", ".jpg", ".xlsx"]};
let fileInfoDir = fileInfos[0];
let subfileInfos = [];
let isDone = false;
try {
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.getRoots(function (err, rootIterator) {
if (err) {
console.error("Failed to getRoots in async, errCode:" + err.code + ", errMessage:" + err.message);
let fileIterator = fileInfoDir.scanFile();
// scanFile() with the filter implementation.
// let fileIterator = rootInfo.scanFile(filter);
if (!fileIterator) {
console.error("scanFile interface returns an undefined object");
return;
}
while (!isDone) {
let result = rootIterator.next();
let result = fileIterator.next();
console.log("next result = " + JSON.stringify(result));
isDone = result.done;
if (!isDone)
rootinfos.push(result.value);
subfileInfos.push(result.value);
}
});
} catch (error) {
console.error("getRoots failed, errCode:" + error.code + ", errMessage:" + error.message);
}
console.error("scanFile failed, errCode:" + error.code + ", errMessage:" + error.message);
}
```
## RootInfo.listfile
## FileIterator
listFile(filter?: Filter) : FileIterator
Provides the **FileIterator** object.
Synchronously obtains the **FileIterator** object of the first-level files (directory) matching the conditions of the filter from the device root node. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Parameters**
### next
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
next() : { value: FileInfo, done: boolean }
Obtains information about the next-level files or directories.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| {value: [FileInfo](#fileinfo), done: boolean} | File or directory information obtained. This method traverses the specified directory until **true** is returned. The **value** field contains the file or directory information obtained.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## RootInfo
Provides the device's root attribute information and APIs.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
### Attributes
| Name| Type | Readable| Writable| Description |
| ------ | ------ | -------- | ------ | -------- |
| deviceType | number | Yes| No|Type of the device.|
| uri | string | Yes| No| Root directory URI of the device.|
| displayName | string | Yes| No| Device name.|
| deviceFlags | number | Yes| No| Capabilities supported by the device.|
### listFile
listFile(filter?: Filter) : FileIterator
Synchronously obtains a **FileIterator** object that lists the first-level files (directories) matching the conditions of the filter from the device root directory and returns [FileInfo](#fileinfo) using [next()](#next). Currently, only built-in storage devices support the file filter.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | [Filter](js-apis-file-fs.md#filter) | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| [FileIterator](#fileiterator) | **FileIterator** object obtained.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -285,7 +409,7 @@ Synchronously obtains the **FileIterator** object of the first-level files (dire
let isDone = false;
try {
let fileIterator = rootInfo.listFile();
// listFile contains the filter implementation.
// listFile() with the filter implementation.
// let fileIterator = rootInfo.listFile(filter);
if (!fileIterator) {
console.error("listFile interface returns an undefined object");
......@@ -303,11 +427,13 @@ Synchronously obtains the **FileIterator** object of the first-level files (dire
}
```
## RootInfo.scanFile
### scanFile
scanFile(filter?: Filter) : FileIterator
Recursively obtains the **FileIterator** object of the files matching the conditions of the filter from the device root node synchronously. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
Synchronously obtains a **FileIterator** object that recursively retrieves the files matching the conditions of the filter from the device root directory and returns [FileInfo](#fileinfo)using [next()](#next). Currently, this API supports only built-in storage devices.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -315,15 +441,19 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | [Filter](js-apis-file-fs.md#filter) | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| [FileIterator](#fileiterator) | **FileIterator** object obtained.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -335,7 +465,7 @@ Recursively obtains the **FileIterator** object of the files matching the condit
let isDone = false;
try {
let fileIterator = rootInfo.scanFile();
// scanFile contains the filter implementation.
// scanFile with the filter implementation.
// let fileIterator = rootInfo.scanFile(filter);
if (!fileIterator) {
console.error("scanFile interface returns undefined object");
......@@ -353,61 +483,106 @@ Recursively obtains the **FileIterator** object of the files matching the condit
}
```
## FileInfo.listfile
## RootIterator
listFile(filter?: Filter) : FileIterator
Provides an iterator object of the device root directory.
Synchronously obtains the **FileIterator** object of the next-level files (directories) matching the conditions of the filter from a directory. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Parameters**
### next
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
next() : { value: RootInfo, done: boolean }
Obtains the root directory of the next-level device.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| {value: [RootInfo](#rootinfo), done: boolean} | Root directory information obtained. This method traverses the directory until **true** is returned. The **value** field contains the root directory information.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## FileAccessHelper
Provides a **FileAccessHelper** object.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
### getRoots
getRoots() : Promise&lt;RootIterator&gt;
Obtains information about the device root nodes of the file management service connected to the **Helper** object. This API uses a promise to return a **RootIterator** object,
which returns [RootInfo](#rootinfo) by using [next](#next-1).
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;[RootIterator](#rootiterator)&gt; | Promise used to return the **RootIterator** object obtained.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
// fileInfoDir specifies the target directory.
// let filter = { suffix : [".txt", ".jpg", ".xlsx"] };
let fileInfoDir = fileInfos[0];
let subfileInfos = [];
async getRoots() {
let rootIterator = null;
let rootinfos = [];
let isDone = false;
try {
let fileIterator = fileInfoDir.listFile();
// listFile contains the filter implementation.
// let fileIterator = rootInfo.listFile(filter);
if (!fileIterator) {
console.error("listFile interface returns an undefined object");
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
rootIterator = await fileAccessHelper.getRoots();
if (!rootIterator) {
console.error("getRoots interface returns an undefined object");
return;
}
while (!isDone) {
let result = fileIterator.next();
let result = rootIterator.next();
console.log("next result = " + JSON.stringify(result));
isDone = result.done;
if (!isDone)
subfileInfos.push(result.value);
rootinfos.push(result.value);
}
} catch (error) {
console.error("listFile failed, errCode:" + error.code + ", errMessage:" + error.message);
console.error("getRoots failed, errCode:" + error.code + ", errMessage:" + error.message);
}
}
```
## FileInfo.scanfile
### getRoots
scanFile(filter?: Filter) : FileIterator;
getRoots(callback:AsyncCallback&lt;RootIterator&gt;) : void
Recursively obtains the **FileIterator** object of the files matching the conditions of the filter from a directory synchronously. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
Obtains information about the device root nodes of the file management service connected to the **Helper** object. This API uses an asynchronous callback to return a **RootIterator** object,
which returns [RootInfo](#rootinfo) by using [next](#next-1).
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -416,50 +591,48 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;[RootIterator](#rootiterator)&gt; | Yes| Callback invoked to return the **RootIterator** object obtained.|
**Return value**
**Error codes**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
// fileInfoDir specifies the target directory.
// let filter = {suffix : [".txt", ".jpg", ".xlsx"]};
let fileInfoDir = fileInfos[0];
let subfileInfos = [];
async getRoots() {
let rootinfos = [];
let isDone = false;
try {
let fileIterator = fileInfoDir.scanFile();
// scanFile contains the filter implementation.
// let fileIterator = rootInfo.scanFile(filter);
if (!fileIterator) {
console.error("scanFile interface returns an undefined object");
// Obtain fileAccessHelper by referring to the sample code of fileAccess.createFileAccessHelper.
fileAccessHelper.getRoots(function (err, rootIterator) {
if (err) {
console.error("Failed to getRoots in async, errCode:" + err.code + ", errMessage:" + err.message);
return;
}
while (!isDone) {
let result = fileIterator.next();
let result = rootIterator.next();
console.log("next result = " + JSON.stringify(result));
isDone = result.done;
if (!isDone)
subfileInfos.push(result.value);
rootinfos.push(result.value);
}
});
} catch (error) {
console.error("scanFile failed, errCode:" + error.code + ", errMessage:" + error.message);
console.error("getRoots failed, errCode:" + error.code + ", errMessage:" + error.message);
}
}
```
## FileAccessHelper.createFile
### createFile
createFile(uri: string, displayName: string) : Promise&lt;string&gt;
Creates a file in a directory. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -468,7 +641,7 @@ Creates a file in a directory. This API uses a promise to return the result.
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| uri | string | Yes| URI of the destination directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
**Return value**
......@@ -477,6 +650,10 @@ Creates a file in a directory. This API uses a promise to return the result.
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the file created.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
......@@ -499,12 +676,14 @@ Creates a file in a directory. This API uses a promise to return the result.
};
```
## FileAccessHelper.createFile
### createFile
createFile(uri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void;
createFile(uri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void
Creates a file in a directory. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -513,9 +692,13 @@ Creates a file in a directory. This API uses an asynchronous callback to return
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| uri | string | Yes| URI of the destination directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file created.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the URI of the file created.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -539,12 +722,14 @@ Creates a file in a directory. This API uses an asynchronous callback to return
};
```
## FileAccessHelper.mkDir
### mkDir
mkDir(parentUri: string, displayName: string) : Promise&lt;string&gt;
Creates a directory. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -553,7 +738,7 @@ Creates a directory. This API uses a promise to return the result.
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| parentUri | string | Yes| URI of the destination directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
**Return value**
......@@ -562,6 +747,10 @@ Creates a directory. This API uses a promise to return the result.
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the directory created.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
......@@ -584,12 +773,14 @@ Creates a directory. This API uses a promise to return the result.
};
```
## FileAccessHelper.mkDir
### mkDir
mkDir(parentUri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void;
mkDir(parentUri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void
Creates a directory. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -598,9 +789,13 @@ Creates a directory. This API uses an asynchronous callback to return the result
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| parentUri | string | Yes| URI of the destination directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the directory created.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the URI of the directory created.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -624,12 +819,14 @@ Creates a directory. This API uses an asynchronous callback to return the result
};
```
## FileAccessHelper.openFile
### openFile
openFile(uri: string, flags: OPENFLAGS) : Promise&lt;number&gt;
Opens a file. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -645,7 +842,11 @@ Opens a file. This API uses a promise to return the result.
| Type| Description|
| --- | -- |
| Promise&lt;number&gt; | Promise used to return the file descriptor of the file opened.|
| Promise&lt;number&gt; | Promise used to return the file descriptor (FD) of the file opened.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -662,12 +863,14 @@ Opens a file. This API uses a promise to return the result.
};
```
## FileAccessHelper.openFile
### openFile
openFile(uri: string, flags: OPENFLAGS, callback: AsyncCallback&lt;number&gt;) : void;
openFile(uri: string, flags: OPENFLAGS, callback: AsyncCallback&lt;number&gt;) : void
Opens a file. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -678,7 +881,11 @@ Opens a file. This API uses an asynchronous callback to return the result.
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the file descriptor of the file opened.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the FD of the file opened.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -701,12 +908,14 @@ Opens a file. This API uses an asynchronous callback to return the result.
};
```
## FileAccessHelper.delete
### delete
delete(uri: string) : Promise&lt;number&gt;
Deletes a file or directory. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -723,6 +932,10 @@ Deletes a file or directory. This API uses a promise to return the result.
| --- | -- |
| Promise&lt;number&gt | Promise used to return the result.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
......@@ -740,12 +953,14 @@ Deletes a file or directory. This API uses a promise to return the result.
};
```
## FileAccessHelper.delete
### delete
delete(uri: string, callback: AsyncCallback&lt;number&gt;) : void;
delete(uri: string, callback: AsyncCallback&lt;number&gt;) : void
Deletes a file or directory. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -755,7 +970,11 @@ Deletes a file or directory. This API uses an asynchronous callback to return th
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to delete.|
| callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the result.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the result.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -778,11 +997,13 @@ Deletes a file or directory. This API uses an asynchronous callback to return th
};
```
## FileAccessHelper.move
### move
move(sourceFile: string, destFile: string) : Promise&lt;string&gt;
Moves a file or directory. This API uses a promise to return the result.
Moves a file or directory. This API uses a promise to return the result. Currently, this API does not support move of files or directories across devices.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -793,7 +1014,7 @@ Moves a file or directory. This API uses a promise to return the result.
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
| destFile | string | Yes| URI of the destination directory, to which the file or directory will be moved.|
**Return value**
......@@ -801,6 +1022,10 @@ Moves a file or directory. This API uses a promise to return the result.
| ----- | ------ |
| Promise&lt;string&gt; | Promise used to return the URI of the file or directory in the destination directory.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
......@@ -818,11 +1043,13 @@ Moves a file or directory. This API uses a promise to return the result.
};
```
## FileAccessHelper.move
### move
move(sourceFile: string, destFile: string, callback: AsyncCallback&lt;string&gt;) : void;
move(sourceFile: string, destFile: string, callback: AsyncCallback&lt;string&gt;) : void
Moves a file or directory. This API uses an asynchronous callback to return the result.
Moves a file or directory. This API uses an asynchronous callback to return the result. Currently, this API does not support move of files or directories across devices.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -833,8 +1060,12 @@ Moves a file or directory. This API uses an asynchronous callback to return the
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file or directory in the destination directory.|
| destFile | string | Yes| URI of the destination directory, to which the file or directory will be moved.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the URI of the file or directory in the destination directory.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -858,12 +1089,14 @@ Moves a file or directory. This API uses an asynchronous callback to return the
};
```
## FileAccessHelper.rename
### rename
rename(uri: string, displayName: string) : Promise&lt;string&gt;
Renames a file or directory. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -881,6 +1114,10 @@ Renames a file or directory. This API uses a promise to return the result.
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the renamed file or directory.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
......@@ -897,12 +1134,14 @@ Renames a file or directory. This API uses a promise to return the result.
};
```
## FileAccessHelper.rename
### rename
rename(uri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void;
rename(uri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void
Renames a file or directory. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -913,7 +1152,11 @@ Renames a file or directory. This API uses an asynchronous callback to return th
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to rename.|
| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the renamed file or directory.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the URI of the renamed file or directory.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -936,12 +1179,14 @@ Renames a file or directory. This API uses an asynchronous callback to return th
};
```
## FileAccessHelper.access
### access
access(sourceFileUri: string) : Promise&lt;boolean&gt;
Checks whether a file or directory exists. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -958,6 +1203,10 @@ Checks whether a file or directory exists. This API uses a promise to return the
| --- | -- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
```js
......@@ -977,12 +1226,14 @@ Checks whether a file or directory exists. This API uses a promise to return the
};
```
## FileAccessHelper.access
### access
access(sourceFileUri: string, callback: AsyncCallback&lt;boolean&gt;) : void;
access(sourceFileUri: string, callback: AsyncCallback&lt;boolean&gt;) : void
Checks whether a file or directory exists. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the stage model.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
......@@ -992,7 +1243,11 @@ Checks whether a file or directory exists. This API uses an asynchronous callbac
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or directory.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the result.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback invoked to return the result.|
**Error codes**
For details about error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example**
......@@ -1018,74 +1273,6 @@ Checks whether a file or directory exists. This API uses an asynchronous callbac
};
```
## RootIterator.next
next( ) : { value: RootInfo, done: boolean }
Obtains the next-level device root directory. **RootIterator** is an iterator object of the device root directory.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Return value**
| Type| Description|
| --- | -- |
| {value: RootInfo, done: boolean} | Root directory information obtained. This API traverses the directory until **done** returns **true**. The **value** field contains the root directory information.|
## FileIterator.next
next( ) : { value: FileInfo, done: boolean }
Obtains the information about the next-level file or directory. **FileIterator** is an iterator object of a directory.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
**Return value**
| Type| Description|
| --- | -- |
| {value: FileInfo, done: boolean} | File or directory information obtained. This API traverses the specified directory until **done** returns **true**. The **value** field contains the file or directory information obtained.|
## RootInfo
Represents the root attribute information and interface capabilities of a device.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
### Attributes
| Name| Type | Readable| Writable| Description |
| ------ | ------ | -------- | ------ | -------- |
| deviceType | number | Yes| No|Device type.|
| uri | string | Yes| No| Root directory URI of the device.|
| displayName | string | Yes| No| Device name.|
| deviceFlags | number | Yes| No| Capabilities supported by the device.|
## FileInfo
Represents the file or directory attribute information and interface capabilities.
**System capability**: SystemCapability.FileManagement.UserFileService
**Required permissions**: ohos.permission.FILE_ACCESS_MANAGER
### Attributes
| Name| Type | Readable| Writable| Description |
| ------ | ------ | -------- | ------ | -------- |
| uri | string | Yes| No| URI of the file or directory.|
| fileName | string | Yes| No| Name of a file or directory.|
| mode | number | Yes| No| Permissions on the file or directory.|
| size | number | Yes| No| Size of the file or directory.|
| mtime | number | Yes| No| Time when the file or directory was last modified.|
| mimeType | string | Yes| No| MIME type of the file or directory.|
## OPENFLAGS
Enumerates the modes for opening a file.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册