HarmonyOS 在cachedir/filedir创建文件夹报错

在cachedir/filedir创建文件夹报错,已经申请了权限

HarmonyOS
2024-12-27 16:32:36
2592浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

创建文件使用的是mkdir方法,API使用出现错误,可以参考此篇文档:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-file-fs-V5

同时请参考此Demo

import { fileIo } from '@kit.CoreFileKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';
  private context = getContext(this) as common.UIAbilityContext;
  readSyn = () => {
    let pathDir = "/data/storage/el2/base/files/"
    let newDirPath = pathDir + "/testDir"
    fileIo.mkdir(newDirPath).then(() => {
      console.info("mkdir succeed");
    }).catch((err: BusinessError) => {
      console.error("mkdir failed with error message: " + err.message + ", error code: " + err.code);
    });

  }

  build() {
    Row() {
      Column() {
        Button(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(()=>{
            this.readSyn()
          })
      }
      .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.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
分享
微博
QQ
微信
回复
2024-12-27 18:06:11
相关问题
怎样根目录中创建文件夹
5359浏览 • 1回复 待解决
HarmonyOS 如何创建文件
662浏览 • 1回复 待解决
打包包含ohosTest文件夹和test文件夹
1693浏览 • 1回复 待解决
HarmonyOS 创建文件的消失了?
693浏览 • 1回复 待解决
如何打开指定文件夹,选择文件返回
9878浏览 • 1回复 待解决
HarmonyOS rawFile文件夹合并问题
1003浏览 • 1回复 待解决
HarmonyOS 获取手机图片文件夹
1204浏览 • 0回复 待解决
apache下文件夹没有访问权限
3331浏览 • 0回复 待解决
HarmonyOS 下载文件到指定文件夹
1026浏览 • 1回复 待解决
单个文件夹空间的统计
1746浏览 • 1回复 待解决
如何实现文件不存在则创建文件
2908浏览 • 1回复 待解决
HarmonyOS 图片文件夹获取封面图coverUri
1123浏览 • 1回复 待解决
HarmonyOS 原有Flutter项目增加ohos文件夹
983浏览 • 1回复 待解决