中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何修改文件最近访问时间属性?
微信扫码分享
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+"abc").then((file:fs.File)=>{ fs.writeSync(file.fd, 'test data'); fs.closeSync(file); //修改最近访问时间 fs.utimes(file.path, new Date().getTime()) }) }) } .width('100%') } .height('100%') } }