未验证 提交 77dad670 编写于 作者: O openharmony_ci 提交者: Gitee

!6395 [翻译完成】#I5EYJR

Merge pull request !6395 from Annie_wang/PR6194
# File Interaction
> **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 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.
......@@ -12,28 +12,29 @@ import document from '@ohos.document';
## 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 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 |
| ------ | ------ | ---- | ---------------------------- |
| type | string[] | No | Type of the file to choose. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------- |
| types | string[] | No | Type of the file to choose.|
- Return value
**Return value**
| Type | Description |
| --------------------- | -------------- |
| Promise&lt;string&gt; | Promise used to return the result. An error code is returned. |
| Type | Description |
| --------------------- | -------------- |
| Promise&lt;string&gt; | Promise used to return the result. An error code is returned.|
- Example
**Example**
```js
await document.choose(type);
let types = [];
document.choose(types);
```
## document.choose
......@@ -41,91 +42,98 @@ choose(callback:AsyncCallback&lt;string&gt;): void
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 |
| -------- | --------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. An error code is returned. |
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. An error code is returned.|
- Example
**Example**
```js
await document.choose(function(err, uri) {
let uri = "";
document.choose(function(err, uri) {
// Do something with the URI.
});
```
## 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 API 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 |
| -------- | --------------------------- | ---- | ---------------------------- |
| type | 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. |
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------- |
| 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.|
- Example
**Example**
```js
await document.choose(type, function(err, uri) {
let types = [];
let uri = "";
document.choose(types, function(err, uri) {
// Do something with the URI.
});
```
## document.show
show(url:string, type:string):Promise&lt;number&gt;
show(uri:string, type:string):Promise&lt;void&gt;
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 |
| ---- | ------ | ---- | ---------------------------- |
| uri | string | Yes | URI of the file to open. |
| type | string | Yes | Type of the file to open. |
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------------- |
| uri | string | Yes | URI of the file to open.|
| type | string | Yes | Type of the file to open.|
- Return value
**Return value**
| Type | Description |
| --------------------- | ------------ |
| Promise&lt;void&gt; | Promise used to return the result. An error code is returned. |
| Type | Description |
| --------------------- | ------------ |
| Promise&lt;void&gt; | Promise used to return the result. An error code is returned.|
- Example
**Example**
```js
await document.show(uri, type);
let type = "";
let uri = "";
document.show(uri, type);
```
## 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 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 |
| -------- | --------------------------- | ---- | ---------------------------- |
| uri | string | Yes | URI 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. |
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------- |
| uri | string | Yes | URI 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. |
- Example
**Example**
```js
await document.show(uri, type, function(err) {
let type = "";
let uri = "";
document.show(uri, type, function(err) {
//do something
});
```
......@@ -3,7 +3,7 @@
> **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.
The APIs of this module can be used to obtain and set file security levels.
Manages file data security levels, including obtaining and setting file data security levels.
## Modules to Import
......@@ -15,34 +15,26 @@ import securityLabel from '@ohos.securityLabel';
Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Application sandbox path of a file or directory = Application directory + File name or directory name
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the application sandbox path of the file is as follows:
```js
let path = dir + "/xxx.txt";
```
The file descriptor is as follows:
```js
let fd = fileio.openSync(path, 0o102, 0o666);
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let path = context.getFilesDir();
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string):Promise&lt;void&gt;
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.DistributedFile
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| dataLevel | string | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
**Return value**
......@@ -53,7 +45,8 @@ Sets the security label for a file in asynchronous mode. This API uses a promise
**Example**
```js
securityLabel.setSecurityLabel(path, dataLevel).then(function(){
let type = "s4";
securityLabel.setSecurityLabel(path, type).then(function(){
console.info("setSecurityLabel successfully");
}).catch(function(error){
console.info("setSecurityLabel failed with error:" + error);
......@@ -62,46 +55,48 @@ Sets the security label for a file in asynchronous mode. This API uses a promise
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback&lt;void&gt;):void
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.DistributedFile
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| dataLevel | string | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
| 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
securityLabel.setSecurityLabel(path, dataLevel, function(error){
let type = "s4";
securityLabel.setSecurityLabel(path, type, function(error){
console.info("setSecurityLabel:" + JSON.stringify(error));
});
```
## securityLabel.setSecurityLabelSync
setSecurityLabelSync(path:string, dataLevel:string):void
setSecurityLabelSync(path:string, type:dataLevel):void
Sets the security label for a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | Yes | File path. |
| dataLevel | string | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
| type | dataLevel | Yes | File security level, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.|
**Example**
```js
securityLabel.setSecurityLabelSync(path, dataLevel);
let type = "s4";
securityLabel.setSecurityLabelSync(path, type);
```
## securityLabel.getSecurityLabel
......@@ -110,7 +105,7 @@ getSecurityLabel(path:string):Promise&lt;string&gt;
Obtains the security label of a file in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
......@@ -127,8 +122,9 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi
**Example**
```js
securityLabel.getSecurityLabel(path).then(function(dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel);
let type = "s4";
securityLabel.getSecurityLabel(path).then(function(type){
console.log("getSecurityLabel successfully:" + type);
}).catch(function(error){
console.log("getSecurityLabel failed with error:" + error);
});
......@@ -140,7 +136,7 @@ getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
Obtains the security label of a file in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
......@@ -152,8 +148,9 @@ Obtains the security label of a file in asynchronous mode. This API uses a callb
**Example**
```js
securityLabel.getSecurityLabel(function(error, dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel);
let type = "s4";
securityLabel.getSecurityLabel(path,function(error, type){
console.log("getSecurityLabel successfully:" + type);
});
```
## securityLabel.getSecurityLabelSync
......@@ -162,7 +159,7 @@ getSecurityLabelSync(path:string):string
Obtains the security label of a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.DistributedFile
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册