#鸿蒙学习大百科#如何修改文件最近访问时间属性?

如何修改文件最近访问时间属性?

HarmonyOS
2024-10-17 09:10:46
浏览
收藏 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+"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%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
分享
微博
QQ
微信
回复
2024-10-17 14:43:49
相关问题
#鸿蒙学习大百科#什么是用户文件
1056浏览 • 0回复 待解决