中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何将文件描述符转化为File?
微信扫码分享
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%') } }