#鸿蒙学习大百科#如何将文件描述符转化为File?

如何将文件描述符转化为File?

HarmonyOS
2024-10-16 08:43:26
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
懂事的小马
import { common } from '@kit.AbilityKit';
import fs from '@ohos.file.fs';
@Entry
@Component
struct Index {
  private context = getContext(this) as common.UIAbilityContext;
  build() {
    Row() {
      Column() {
        Text("Hello")
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let applicationContext = this.context.getApplicationContext();
            let cacheDir = applicationContext.cacheDir;
            fs.open(cacheDir + "/aaa", fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE).then((file: fs.File) => {
              let fd = file.fd
              let file2 = fs.dup(fd) //将file的fd转换为file2
              fs.close(file)
              fs.close(file2)
            })
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-10-16 15:12:02
相关问题
如何将一张图片转化为PixelMapElement
9983浏览 • 1回复 待解决