提交 0f75deab 编写于 作者: U unknown

add user

Signed-off-by: Nunknown <sijunjie@huawei.com>
上级 70448f29
...@@ -76,22 +76,22 @@ FA模型中,可以通过featureAbility的getContext接口获取应用上下文 ...@@ -76,22 +76,22 @@ FA模型中,可以通过featureAbility的getContext接口获取应用上下文
通过getContext获取应用上下文并获取分布式目录的示例如下: 通过getContext获取应用上下文并获取分布式目录的示例如下:
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility';
import fileIo from '@ohos.fileio' import fs from '@ohos.file.fs';
(async () => { (async () => {
let dir: string let dir: string;
try { try {
console.info('Begin to getOrCreateDistributedDir') console.info('Begin to getOrCreateDistributedDir');
dir = await featureAbility.getContext().getOrCreateDistributedDir() dir = await featureAbility.getContext().getOrCreateDistributedDir();
console.info('distribute dir is ' + dir) console.info('distribute dir is ' + dir)
} catch (error) { } catch (error) {
console.error('getOrCreateDistributedDir failed with ' + error) console.error('getOrCreateDistributedDir failed with ' + error);
} }
let fd: number; let fd: number;
let path = dir + "/a.txt"; let path = dir + "/a.txt";
fd = fileIo.openSync(path, 0o2 | 0o100, 0o666); fd = fs.openSync(path, fs.OpenMode.READ_WRITE).fd;
fileIo.close(fd); fs.close(fd);
})() })()
``` ```
...@@ -130,11 +130,11 @@ import Want from '@ohos.app.ability.Want'; ...@@ -130,11 +130,11 @@ import Want from '@ohos.app.ability.Want';
``` ```
* 文件描述符(FD) * 文件描述符(FD)
```ts ```ts
import fileio from '@ohos.fileio'; import fs from '@ohos.file.fs';
let fd; let fd;
try { try {
fd = fileio.openSync('/data/storage/el2/base/haps/pic.png'); fd = fs.openSync('/data/storage/el2/base/haps/pic.png').fd;
} catch(e) { } catch(e) {
console.error('openSync fail: ${JSON.stringify(e)}'); console.error('openSync fail: ${JSON.stringify(e)}');
} }
......
...@@ -108,10 +108,10 @@ import Want from '@ohos.application.Want'; ...@@ -108,10 +108,10 @@ import Want from '@ohos.application.Want';
``` ```
* 文件描述符(FD) * 文件描述符(FD)
```ts ```ts
import fileio from '@ohos.fileio'; import fs from '@ohos.file.fs';
let fd; let fd;
try { try {
fd = fileio.openSync('/data/storage/el2/base/haps/pic.png'); fd = fs.openSync('/data/storage/el2/base/haps/pic.png').fd;
} catch(e) { } catch(e) {
console.error('openSync fail: ${JSON.stringify(e)}'); console.error('openSync fail: ${JSON.stringify(e)}');
} }
......
...@@ -41,12 +41,12 @@ Want是对象间信息传递的载体, 可以用于应用组件间的信息传 ...@@ -41,12 +41,12 @@ Want是对象间信息传递的载体, 可以用于应用组件间的信息传
- 传递FD(文件描述符)数据(在UIAbility对象中调用,其中示例中的context为UIAbility的上下文对象) - 传递FD(文件描述符)数据(在UIAbility对象中调用,其中示例中的context为UIAbility的上下文对象)
```ts ```ts
import fileio from '@ohos.fileio'; import fs from '@ohos.file.fs';
// ... // ...
let fd; let fd;
try { try {
fd = fileio.openSync('/data/storage/el2/base/haps/pic.png'); fd = fs.openSync('/data/storage/el2/base/haps/pic.png').fd;
} catch(e) { } catch(e) {
console.error('openSync fail: ${JSON.stringify(e)}'); console.error('openSync fail: ${JSON.stringify(e)}');
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册