未验证 提交 6519ac1b 编写于 作者: O openharmony_ci 提交者: Gitee

!5977 文档修改

Merge pull request !5977 from wangbo/master
...@@ -12,7 +12,7 @@ import document from '@ohos.document'; ...@@ -12,7 +12,7 @@ import document from '@ohos.document';
## document.choose ## document.choose
choose(type:string[]): Promise<string> choose(types:string[]): Promise<string>
通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。 通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。
...@@ -22,7 +22,7 @@ choose(type:string[]): Promise<string> ...@@ -22,7 +22,7 @@ choose(type:string[]): Promise<string>
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------------------------- | | ------ | ------ | ---- | ---------------------------- |
| type | string[] | 否 | 限定文件选择的类型 | | types | string[] | 否 | 限定文件选择的类型 |
- 返回值: - 返回值:
...@@ -33,7 +33,8 @@ choose(type:string[]): Promise<string> ...@@ -33,7 +33,8 @@ choose(type:string[]): Promise<string>
- 示例: - 示例:
```js ```js
await document.choose(type); let tpyes = [];
document.choose(types);
``` ```
## document.choose ## document.choose
...@@ -52,13 +53,14 @@ choose(callback:AsyncCallback<string>): void ...@@ -52,13 +53,14 @@ choose(callback:AsyncCallback<string>): void
- 示例: - 示例:
```js ```js
await document.choose(function(err, uri) { let uri = "";
document.choose(function(err, uri) {
//do something with uri //do something with uri
}); });
``` ```
## document.choose ## document.choose
choose(type:string[], callback:AsyncCallback<string>): void choose(types:string[], callback:AsyncCallback<string>): void
通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。 通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。
...@@ -68,20 +70,22 @@ choose(type:string[], callback:AsyncCallback<string>): void ...@@ -68,20 +70,22 @@ choose(type:string[], callback:AsyncCallback<string>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| type | string[] | 否 | 限定选择文件的类型 | | types | string[] | 否 | 限定选择文件的类型 |
| callback | AsyncCallback<string> | 是 | 异步获取对应文件URI(注:当前返回错误码) | | callback | AsyncCallback<string> | 是 | 异步获取对应文件URI(注:当前返回错误码) |
- 示例: - 示例:
```js ```js
await document.choose(type, function(err, uri) { let types = [];
let uri = "";
document.choose(types, function(err, uri) {
//do something with uri //do something with uri
}); });
``` ```
## document.show ## document.show
show(url:string, type:string):Promise<number> show(url:string, types:string):Promise<number>
异步打开URI对应的文件,使用promise形式返回结果。 异步打开URI对应的文件,使用promise形式返回结果。
...@@ -92,7 +96,7 @@ show(url:string, type:string):Promise<number> ...@@ -92,7 +96,7 @@ show(url:string, type:string):Promise<number>
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ---------------------------- | | ---- | ------ | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI | | uri | string | 是 | 待打开的文件URI |
| type | string | 是 | 待打开文件的类型 | | types | string | 是 | 待打开文件的类型 |
- 返回值: - 返回值:
...@@ -103,12 +107,14 @@ show(url:string, type:string):Promise<number> ...@@ -103,12 +107,14 @@ show(url:string, type:string):Promise<number>
- 示例: - 示例:
```js ```js
await document.show(uri, type); let types = "";
let uri = "";
document.show(uri, types);
``` ```
## document.show ## document.show
show(url:string, type:string, callback:AsyncCallback<void>): void show(url:string, types:string, callback:AsyncCallback<void>): void
异步打开URI对应的文件,使用callback形式返回结果。 异步打开URI对应的文件,使用callback形式返回结果。
...@@ -119,13 +125,15 @@ show(url:string, type:string, callback:AsyncCallback<void>): void ...@@ -119,13 +125,15 @@ show(url:string, type:string, callback:AsyncCallback<void>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI | | uri | string | 是 | 待打开的文件URI |
| type | string | 是 | 待打开文件的类型 | | types | string | 是 | 待打开文件的类型 |
| callback | AsyncCallback<void> | 是 | 异步打开uri对应文件(注:当前返回错误码) | | callback | AsyncCallback<void> | 是 | 异步打开uri对应文件(注:当前返回错误码) |
- 示例: - 示例:
```js ```js
await document.show(uri, type, function(err) { let types = "";
let uri = "";
document.show(uri, types, function(err) {
//do something //do something
}); });
``` ```
......
...@@ -111,7 +111,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -111,7 +111,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
```js ```js
// 获取目录下所有文件 // 获取目录下所有文件
// 通过listFile、getRoot获取的文件uri // 通过listFile、getRoot获取的文件uri
let media_path = file.path let media_path = ""
filemanager.listFile(media_path, "file") filemanager.listFile(media_path, "file")
.then((fileInfo) => { .then((fileInfo) => {
if(Array.isArray(fileInfo)) { if(Array.isArray(fileInfo)) {
...@@ -120,6 +120,9 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -120,6 +120,9 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
} }
} }
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
}); });
``` ```
...@@ -152,7 +155,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -152,7 +155,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
```js ```js
// 通过listFile、getRoot获取的文件path // 通过listFile、getRoot获取的文件path
let fileInfos = await filemanager.getRoot(); let fileInfos = filemanager.getRoot();
let media_path = ""; let media_path = "";
for (let i = 0; i < fileInfos.length; i++) { for (let i = 0; i < fileInfos.length; i++) {
if (fileInfos[i].name == "image_album") { if (fileInfos[i].name == "image_album") {
...@@ -197,7 +200,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P ...@@ -197,7 +200,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
| 类型 | 说明 | | 类型 | 说明 |
| --- | -- | | --- | -- |
| Promise&lt;string&gt; | 文件uri | | string | 文件uri |
- 异常 - 异常
| 错误名称 | 错误类型 | 错误码 |说明 | | 错误名称 | 错误类型 | 错误码 |说明 |
...@@ -211,7 +214,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P ...@@ -211,7 +214,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
```js ```js
// 创建文件,返回文件uri // 创建文件,返回文件uri
let media_path = file.uri // 通过listFile、getRoot获取的文件uri let media_path = "" // 通过listFile、getRoot获取的文件uri
let name = "xxx.jpg" // 待保存文件的后缀 let name = "xxx.jpg" // 待保存文件的后缀
filemanager.createFile(media_path, name).then((uri) => { filemanager.createFile(media_path, name).then((uri) => {
// 返回uri给应用 // 返回uri给应用
...@@ -252,13 +255,15 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -252,13 +255,15 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
```js ```js
// 创建文件,返回文件uri // 创建文件,返回文件uri
// 通过listFile、getRoot获取的文件uri // 通过listFile、getRoot获取的文件uri
let media_path = file.path let media_path = ""
// 待保存文件的后缀 // 待保存文件的后缀
let name = "xxx.jpg" let name = "xxx.jpg"
filemanager.createFile(media_path, name, (err, uri) => { let dev = "";
filemanager.createFile(media_path, name, { DevInfo: dev }, function(err, uri) {
// 返回uri给应用 // 返回uri给应用
console.log("file uri:"+uri); console.log("file uri:"+uri);
}); });
``` ```
## FileInfo ## FileInfo
......
...@@ -13,20 +13,12 @@ import securityLabel from '@ohos.securityLabel'; ...@@ -13,20 +13,12 @@ import securityLabel from '@ohos.securityLabel';
## 使用说明 ## 使用说明
使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考:[Context模块的接口getOrCreateLocalDir](js-apis-Context.md) 使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考:
“文件/目录应用沙箱路径”=“应用目录路径”+“文件/目录名”
通过上述接口获取到应用目录路径dir,文件名为“xxx.txt”,文件所在应用沙箱路径为:
```js
let path = dir + "/xxx.txt";
```
文件描述符fd:
```js ```js
let fd = fileio.openSync(path, 0o102, 0o666); import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let path = context.getFilesDir();
``` ```
## securityLabel.setSecurityLabel ## securityLabel.setSecurityLabel
...@@ -53,6 +45,7 @@ setSecurityLabel(path:string, dataLevel:string):Promise&lt;void&gt; ...@@ -53,6 +45,7 @@ setSecurityLabel(path:string, dataLevel:string):Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let dataLevel = "s4";
securityLabel.setSecurityLabel(path, dataLevel).then(function(){ securityLabel.setSecurityLabel(path, dataLevel).then(function(){
console.info("setSecurityLabel successfully"); console.info("setSecurityLabel successfully");
}).catch(function(error){ }).catch(function(error){
...@@ -79,6 +72,7 @@ setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback&lt;void& ...@@ -79,6 +72,7 @@ setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback&lt;void&
**示例:** **示例:**
```js ```js
let dataLevel = "s4";
securityLabel.setSecurityLabel(path, dataLevel, function(error){ securityLabel.setSecurityLabel(path, dataLevel, function(error){
console.info("setSecurityLabel:" + JSON.stringify(error)); console.info("setSecurityLabel:" + JSON.stringify(error));
}); });
...@@ -101,6 +95,7 @@ setSecurityLabelSync(path:string, dataLevel:string):void ...@@ -101,6 +95,7 @@ setSecurityLabelSync(path:string, dataLevel:string):void
**示例:** **示例:**
```js ```js
let dataLevel = "s4";
securityLabel.setSecurityLabelSync(path, dataLevel); securityLabel.setSecurityLabelSync(path, dataLevel);
``` ```
...@@ -127,6 +122,7 @@ getSecurityLabel(path:string):Promise&lt;string&gt; ...@@ -127,6 +122,7 @@ getSecurityLabel(path:string):Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
let dataLevel = "s4";
securityLabel.getSecurityLabel(path).then(function(dataLevel){ securityLabel.getSecurityLabel(path).then(function(dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel); console.log("getSecurityLabel successfully:" + dataLevel);
}).catch(function(error){ }).catch(function(error){
...@@ -152,7 +148,8 @@ getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void ...@@ -152,7 +148,8 @@ getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
securityLabel.getSecurityLabel(function(error, dataLevel){ let dataLevel = "s4";
securityLabel.getSecurityLabel(path,function(error, dataLevel){
console.log("getSecurityLabel successfully:" + dataLevel); console.log("getSecurityLabel successfully:" + dataLevel);
}); });
``` ```
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
## 导入模块 ## 导入模块
```js ```js
import storagestatistics from "@ohos.storageStatistics"; import storageStatistics from "@ohos.storageStatistics";
``` ```
## storagestatistics.getTotalSizeOfVolume ## storagestatistics.getTotalSizeOfVolume
...@@ -227,7 +227,7 @@ getCurrentBundleStats(): Promise<BundleStats> ...@@ -227,7 +227,7 @@ getCurrentBundleStats(): Promise<BundleStats>
- 示例 - 示例
```js ```js
let bundleStats = await storageStatistics.getCurrentBundleStats(); let bundleStats = storageStatistics.getCurrentBundleStats();
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
``` ```
...@@ -292,7 +292,7 @@ getTotalSize(): Promise<number> ...@@ -292,7 +292,7 @@ getTotalSize(): Promise<number>
- 示例 - 示例
```js ```js
let number = await storageStatistics.getTotalSize(); let number = storageStatistics.getTotalSize();
console.info("getTotalSize successfully:"+ JSON.stringify(number)); console.info("getTotalSize successfully:"+ JSON.stringify(number));
``` ```
...@@ -345,7 +345,7 @@ getFreeSize(): Promise<number> ...@@ -345,7 +345,7 @@ getFreeSize(): Promise<number>
- 示例 - 示例
```js ```js
let number = await storageStatistics.getFreeSize(); let number = storageStatistics.getFreeSize();
console.info("getFreeSize successfully:"+ JSON.stringify(number)); console.info("getFreeSize successfully:"+ JSON.stringify(number));
``` ```
...@@ -493,6 +493,7 @@ getUserStorageStats(userId?: string, callback:AsyncCallback&lt;StorageStats&gt;) ...@@ -493,6 +493,7 @@ getUserStorageStats(userId?: string, callback:AsyncCallback&lt;StorageStats&gt;)
- 示例 - 示例
```js ```js
let userId = "";
storagestatistics.getUserStorageStats(userId, function(error, StorageStats){ storagestatistics.getUserStorageStats(userId, function(error, StorageStats){
// do something // do something
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册