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

!16805 修复fileio

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