【问题标题】:Ionic checkFile(path,filename) NOT_FOUND_ERR离子检查文件(路径,文件名)NOT_FOUND_ERR
【发布时间】:2023-03-19 15:15:01
【问题描述】:

文件路径 - file:///data/data/io.ionic.starter/data.json

我希望检查上述路径中是否存在“data.json”。

但我收到一个错误 - {"code":1,"message":"NOT_FOUND_ERR"} 目前该文件不存在于路径中,因此我希望 Promise 返回 false,但它最终会引发错误。

示例代码:

var fileName = "data.json";
     this.file.checkFile(this.file.applicationStorageDirectory, fileName)
    .then((result) => {
    console.log('file exists :' + result);
    },(error){
    console.log('error : ' + JSON.stringify(error)});

【问题讨论】:

标签: android ionic-framework ionic2 ionic-native


【解决方案1】:

checkDir 也有同样的问题。

最后我发现了问题。它的工作方式与预期略有不同。

当目录(或您的情况下的文件)存在时,确实会执行 then 部分。当目录不存在时,它不会返回错误值,而是使用代码 1 转到错误部分(捕获)。 所以如果错误码为 1 则表示该文件在目录中不存在。

【讨论】:

    【解决方案2】:

    确认您的dir 参数已传递给checkFile。它应该以“/”结尾。

    【讨论】:

      猜你喜欢
      • 2021-11-09
      • 2019-04-22
      • 1970-01-01
      • 2022-08-17
      • 2016-09-30
      • 2021-06-14
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多