提交 d7a85ce4 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 93c4c64e
# File Interaction # File Interaction
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
- The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
- The APIs of this module will be deprecated and are not recommended for use. An exception will be thrown if any of the APIs is called. > - The APIs of this module will be deprecated and are not recommended for use. An exception will be thrown if any of the APIs is called.
## Modules to Import ## Modules to Import
...@@ -12,109 +12,115 @@ import document from '@ohos.document'; ...@@ -12,109 +12,115 @@ import document from '@ohos.document';
## document.choose ## document.choose
choose(type:string[]): Promise&lt;string&gt; choose(types? : string[]): Promise&lt;string&gt;
Chooses a file of the specified type using the file manager. This method uses a promise to return the result. Chooses a file of the specified type using the file manager. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------- | | ------ | ------ | ---- | ---------------------------- |
| type | string[] | No | Type of the file to choose.| | types | string[] | No | Type of the file to choose.|
- Return value **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------------- | | --------------------- | -------------- |
| Promise&lt;string&gt; | Promise used to return the result. An error code is returned.| | Promise&lt;string&gt; | Promise used to return the result. An error code is returned.|
- Example **Example**
```js ```js
await document.choose(type); let types = [];
document.choose(types);
``` ```
## document.choose ## document.choose
choose(callback:AsyncCallback&lt;string&gt;): void choose(callback:AsyncCallback&lt;string&gt;): void
Chooses a file using the file manager. This method uses an asynchronous callback to return the result. Chooses a file using the file manager. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. An error code is returned.| | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. An error code is returned.|
- Example **Example**
```js ```js
await document.choose(function(err, uri) { let uri = "";
document.choose(function(err, uri) {
// Do something with the URI. // Do something with the URI.
}); });
``` ```
## document.choose ## document.choose
choose(type:string[], callback:AsyncCallback&lt;string&gt;): void choose(types:string[], callback:AsyncCallback&lt;string&gt;): void
Chooses a file of the specified type using the file manager. This method uses an asynchronous callback to return the result. Chooses a file using the file manager. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| type | string[] | No | Type of the file to choose.| | types | string[] | No | Type of the file to choose.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. An error code is returned.| | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. An error code is returned.|
- Example **Example**
```js ```js
await document.choose(type, function(err, uri) { let types = [];
let uri = "";
document.choose(types, function(err, uri) {
// Do something with the URI. // Do something with the URI.
}); });
``` ```
## document.show ## document.show
show(url:string, type:string):Promise&lt;number&gt; show(uri:string, type:string):Promise&lt;void&gt;
Opens a file. This method uses a promise to return the result. Opens a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------------- | | ---- | ------ | ---- | ---------------------------- |
| uri | string | Yes | URI of the file to open.| | uri | string | Yes | URI of the file to open.|
| type | string | Yes | Type of the file to open.| | type | string | Yes | Type of the file to open.|
- Return value **Return value**
| Type | Description | | Type | Description |
| --------------------- | ------------ | | --------------------- | ------------ |
| Promise&lt;void&gt; | Promise used to return the result. An error code is returned.| | Promise&lt;void&gt; | Promise used to return the result. An error code is returned.|
- Example **Example**
```js ```js
await document.show(uri, type); let type = "";
let uri = "";
document.show(uri, type);
``` ```
## document.show ## document.show
show(url:string, type:string, callback:AsyncCallback&lt;void&gt;): void show(uri:string, type:string, callback:AsyncCallback&lt;void&gt;): void
Opens a file. This method uses an asynchronous callback to return the result. Opens a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.UserFileService
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
...@@ -122,10 +128,12 @@ Opens a file. This method uses an asynchronous callback to return the result. ...@@ -122,10 +128,12 @@ Opens a file. This method uses an asynchronous callback to return the result.
| type | string | Yes | Type of the file to open.| | type | string | Yes | Type of the file to open.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. An error code is returned. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. An error code is returned. |
- Example **Example**
```js ```js
await document.show(uri, type, function(err) { let type = "";
let uri = "";
document.show(uri, type, function(err) {
//do something //do something
}); });
``` ```
# Security Label
> **NOTE**<br/>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Manages file data security levels, including obtaining and setting file data security levels.
## Modules to Import
```js
import securityLabel from '@ohos.securityLabel';
```
## Usage
Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
```js
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let path = context.getFilesDir();
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, type:dataLevel):Promise&lt;void&gt;
Sets the security label for a file in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
**Return value**
| Type | Description |
| ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value will be returned.|
**Example**
```js
let type = "s4";
securityLabel.setSecurityLabel(path, type).then(function(){
console.info("setSecurityLabel successfully");
}).catch(function(error){
console.info("setSecurityLabel failed with error:" + error);
});
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, type:dataLevel, callback: AsyncCallback&lt;void&gt;):void
Sets the security label for a file in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example**
```js
let type = "s4";
securityLabel.setSecurityLabel(path, type, function(error){
console.info("setSecurityLabel:" + JSON.stringify(error));
});
```
## securityLabel.setSecurityLabelSync
setSecurityLabelSync(path:string, type:dataLevel):void
Sets the security label for a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
**Example**
```js
let type = "s4";
securityLabel.setSecurityLabelSync(path, type);
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string):Promise&lt;string&gt;
Obtains the security label of a file in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------- |
| path | string | Yes | File path.|
**Return value**
| Type | Description |
| --------------------- | ------------ |
| Promise&lt;string&gt; | Promise used to return the security label obtained.|
**Example**
```js
let type = "s4";
securityLabel.getSecurityLabel(path).then(function(type){
console.log("getSecurityLabel successfully:" + type);
}).catch(function(error){
console.log("getSecurityLabel failed with error:" + error);
});
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
Obtains the security label of a file in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------------- |
| path | string | Yes | File path. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the security label obtained.|
**Example**
```js
let type = "s4";
securityLabel.getSecurityLabel(path,function(error, type){
console.log("getSecurityLabel successfully:" + type);
});
```
## securityLabel.getSecurityLabelSync
getSecurityLabelSync(path:string):string
Obtains the security label of a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------- |
| path | string | Yes | File path.|
**Return value**
| Type | Description |
| ------ | ------------ |
| string | Security label obtained.|
**Example**
```js
let result = securityLabel.getSecurityLabelSync(path);
console.log("getSecurityLabel successfully:" + result);
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册